Reputation: 4214
doing a communication between android client and wcf self-hosted service. Everything works perfect if I send post in Fiddler to the service, but android client gives back "java.net.SocketException: No route to host" when I try to send post. Connecting from real device through wifi to the pc with running service. Did anybody have this issue?
Server:
[ServiceContract]
public interface ISDMobileService
{
[OperationContract]
[WebInvoke(Method="POST",BodyStyle=WebMessageBodyStyle.Bare,ResponseFormat=WebMessageFormat.Xml,RequestFormat=WebMessageFormat.Xml)]
string PostMessage(string SdaMessage);
}
public class Service : ISDMobileService
{
public string PostMessage(string SdaMessage)
{
Console.WriteLine( "Post Message : " + SdaMessage );
return"Calling Post for you " + SdaMessage;
}
}
Client:
String urlToSendRequest = "http://172.16.3.4:7310/PostMessage";
String targetDomain = "172.16.3.4";
HttpClient httpClient = new DefaultHttpClient();
HttpPost request = new HttpPost(urlToSendRequest);
List<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("SdaMessage", "param value one"));
request.addHeader("Content-Type", "application/xml");
try
{
request.setEntity(new UrlEncodedFormEntity(postParameters));
HttpResponse response = httpClient.execute(request);
if(response != null)
{
HttpParams str = response.getParams();
}
}
catch (Exception ex)
{
ex.printStackTrace();
}
Upvotes: 0
Views: 1314
Reputation: 14786
172.16.x.x is in the private IP address range, not accessible from the public internet. If you are trying to connect to there from an Android device that is not on the same private network, it will fail with the error given.
Upvotes: 1