0
在android客户端和wcf自托管服务之间进行通信。如果我将Fiddler中的帖子发送到服务,一切都很完美,但是当我尝试发送帖子时,android客户端会返回“java.net.SocketException:没有路由到主机”。 从真实设备通过wifi连接到运行服务的电脑。 有没有人有这个问题?android-wcf休息服务通信
服务器:
[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;
}
}
客户:
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();
}
谢谢主席先生,这解决了我的问题。 – Maxim
如果我们想测试从Android设备到WCF的请求,IP会是什么? – kavita