我有一個wcf rest服務託管在部署服務器上,我試圖從android設備調用它。我在互聯網上嘗試了幾乎所有的東西,但它仍然無法正常工作,它不斷給我一個錯誤「Endpoint not found」。以下是我的代碼片段從Android設備訪問WCF Rest服務(方法='POST')
的Android代碼:
string url = "http://productionservertmp.com/Service1.svc/PostServiceRequest";
HttpPost httpPost = new HttpPost(url);
JSONObject jobj = new JSONObject();
jobj.put("reqobj", "Greetings from Android client");
StringEntity se = new StringEntity(jobj.toString());
httpPost.setEntity(se);
HttpClient client = new DefaultHttpClient();
response = client.execute(httpPost);
HttpEntity entity = response.getEntity();
String data = null;
JSONArray jsonResponse = null;
try {
data = EntityUtils.toString(entity); //Here's where i find out about response (endpoint not found)
jsonResponse = new JSONArray(data);
} catch (Exception e) {}
//Signature of my function in interface:
[OperationContract]
[WebInvoke(UriTemplate = "PostServiceRequest", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, Method = "POST")]
string PostServiceRequest(string reqobj);
//Method in Implementation class
public string PostServiceRequest(string reqobj)
{
return "Response: "+reqobj;
}
//And in web.config on deployment server, I've following
<services>
<service name="Service1">
<endpoint address="" behaviorConfiguration="restBehavior" bindingConfiguration="" binding="webHttpBinding" contract="IService1">
</endpoint>
</service>
</services>
我在與方法=同一服務的另一個功能「GET」,它的成功調用。問題在於使用POST方法。我錯過了什麼?