2013-10-08 3 views
1

.NET에서 WCF를 사용하여 REST를 사용하여 JSON을 보낼 수있는 방법이 있습니까? 목적은 안드로이드 모바일 클라이언트에서 .NET 서버로 문자열을 보내고 문자열을 추가하여 안드로이드 클라이언트로 다시 보내는 것입니다. 검색은 효율성 문제에 대해 권장되지 않는 SOAP로만 나에게 굴복했습니다.WCF를 사용하지 않는 JSON REST

+0

당신은 서비스를이 .asmx 사용할 수 있지만, 이제 wcf가 더 많이 보급되었습니다. WCF는 Restful JSON 요청도 지원합니다. – Piyush

+0

링크를 가르쳐 주시겠습니까? .asmx가 Restfull json을 지원합니까? 그렇다면 내 안드로이드 클라이언트로부터 어떻게 서비스를 호출 할 수 있습니까? – user2818487

답변

0

Service Stack을 살펴보십시오. JSON을 REST 이상으로 처리합니다.

0

(안드로이드) 클라이언트 측 : 홈페이지 서버 ASHX 서비스에서

http://IP_Address/Login/Register.ashx 

public String SendToWebFunc(List<NameValuePair> postParameters, String URL) 
{ 
HttpClient client1 = new DefaultHttpClient(); 
HttpPost request = new HttpPost(URL); 
String page=""; 
try 
{ 
    request.setEntity(new UrlEncodedFormEntity(postParameters)); 
    UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters); 
    request.setEntity(formEntity); 
    HttpResponse response; 
    response = client1.execute(request); //Sends the actual request 

    //Decode response to string 
    BufferedReader in = new BufferedReader(new  InputStreamReader(response.getEntity().getContent())); 
    String line1; 
    line1 = in.readLine(); 

    while(line1!=null) 
    { 
    page=page+line1; 
     line1=in.readLine(); 
    } 

}   
catch (ClientProtocolException e) 
{ 
      e.printStackTrace(); 
} catch (IOException e) { 
      e.printStackTrace(); 
} 
return page; 
} 

당신이 할 수 있습니다 :

public class Register : IHttpHandler 
{ 

    public void ProcessRequest (HttpContext context) 
    { 
     String data = context.Request.Params["request_data"]; 

     . 
     . 
     . 
     context.Response.Write("false"); 
    } 
} 
+0

클라이언트에게 다시 보내야 할 경우 어떻게해야합니까? – user2818487

관련 문제