2014-07-14 3 views
1

웹 메서드에 Json을 보냈습니다. 웹 메서드는 json을 문자열로받지 않습니다.웹 메서드에서 jsonQuery 문자열 받기

POST 방법 Test1.aspx - Test3.aspx에서

var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://localhost:49633/Test3.aspx/Get"); 

       httpWebRequest.ContentType = "application/json"; 
       httpWebRequest.Method = "POST"; 

       using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream())) 
       { 
        string json = "{\"d\":{\"accessKey\":\"Chennai\",\"channelId\":\"1025\"}}"; 

        streamWriter.Write(json); 
       } 
       var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); 
       using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) 
       { 
        var responseText = streamReader.ReadToEnd(); 
        return responseText; 
       } 

WEB 방법

[System.Web.Services.WebMethod] 
     public static string Get(string d) 
     { 
      return d; 
     } 

RESPONCE -

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

    <html xmlns="http://www.w3.org/1999/xhtml"> 
    <head><title> 

    </title></head> 
    <body> 
     <form name="form1" method="post" action="Booking.aspx" id="form1"> 
    <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTg3NjI4NzkzNmRkOvsswBe8G74mfKP2QBvs0WW2jms=" /> 

     <div> 
    <span id="Label3"><font color="Fuchsia">Responce:-</font></span> 
      <span id="Label1">Label</span> 
     </div> 
     </form> 
    </body> 
    </html> 

QUERY -

응답이 HTML 페이지로 수신됩니다. 하지만 내가 POST 방법을 통해

JSON 문자열 전송 된 JSON 수신 할 - 내가 { "액세스 키"로 JSON 문자열을 변경 한

{"d":{"accessKey":"Chennai","channelId":"1025"}} 

편집을 " Chennai ","channelId ":"1025 "} 문자열을 가져 오기 위해 webmethod를 변경했습니다.

[System.Web.Services.WebMethod] 
      public static string Get(string accessKey, string channelId) 
      { 
       return accessKey + channelId; 
      } 

올바른 채널 ID, 액세스 키 값을 받았습니다. 하지만 내 원래 문자열은 매우 큽니다. 그래서 POST 메서드를 통해 보내는 동일한 Json String을 수신해야합니다. bzs 나는 부분만을 받고있다. 내 고객 한 번이 Websmethod 호출을 통해 Json String을 보냅니다. 감사. 2

편집 MEZ는 내가 가지고있는 ScriptMethod을 포함 말했다 당으로. 하지만 그것을 통해 원격 서버가 오류를 반환했습니다 : (500) 내부 서버 오류.

[System.Web.Services.WebMethod] 

    [ScriptMethod(ResponseFormat = ResponseFormat.Json)] 
      public static string Get(string d) 
      {   
       return d; 
      } 
+0

HTTP 일반 핸들러 사용을 고려하십시오. 링크보기 : http://stackoverflow.com/questions/3702959/asp-net-generic-http-handler-ashx-supporting-jsonp. 귀하의 경우에 일어나고있는 것처럼, 필요하지 않은 콘텐츠를 보내지 않을 것입니다 ... – Mez

+0

문자열을 { "accessKey": "Chennai", "channelId": "1025"}로 변경하고 public으로 webmethod를 변경하면 정적 문자열 Get (string accessKey, string channelId) 값을 가져올 수 있습니다. 하지만 나는 Json Full String을 원한다. – Sagotharan

+0

ScriptMethod 응답 형식도 누락되었습니다 ... – Mez

답변

0

json의 최대 한도에 도달했을 수 있습니다. 이것을 web.config에 추가하십시오.

<configuration> 
    ... 
    <system.web.extensions> 
     <scripting> 
      <webServices> 
       <jsonSerialization maxJsonLength="300000" /> 
      </webServices> 
     </scripting> 
    </system.web.extensions> 
</configuration> 
+0

나는 각하를 시험해 보았습니다. 그러나 원격 서버에서 오류를 반환했습니다 : (500) 내부 서버 오류. 질문에 대한 나의 편집을 참조하십시오. Full Json String을 받아야합니다. @Mez – Sagotharan

+0

내 대답이 업데이트되었습니다. – Mez

+0

길이 문제가 아닙니다. Mez. Im은 Json을받지 못했습니다. { "d": { "accessKey": "Chennai", "channelId": "1025"}} 내 코덱을 시도하고 해결책을 제시하십시오. – Sagotharan

관련 문제