2014-07-17 2 views
1

배포 서버에서 wcf rest 서비스를 호스팅하고 있으며이를 Android 장치에서 호출하려고합니다. 인터넷에서 거의 모든 것을 시도했지만 여전히 작동하지 않습니다. 오류 '엔드 포인트를 찾을 수 없습니다.'가 계속 표시됩니다. 내 코드안드로이드 장치에서 WCF Rest Service (Method = 'POST') 액세스

안드로이드 코드를 다음과 같은 :

  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 메서드 어딘가에있다. 나는 무엇을 놓치고 있습니까? 모든

답변

0

첫째,

서비스 URL에 문제가

:

http://productionservertmp.com/Service1.svc/PostServiceRequest

그것은 브라우저에서 액세스 할 수 없습니다가. 작동하는지 확인하십시오.

포인트 2 : 전송할 서비스 매개 변수가 있으므로 [WebInvoke]를 사용하여 올바르게 구성하십시오.

[WebInvoke의 (UriTemplate = "/ PostServiceRequest/reqobj {}"ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json 방법 = "POST")]

이러한 변경을 시도 .