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