对于wcf服务,Json返回readresponse()失败 [英] Json return readresponse() failed for wcf service

查看:69
本文介绍了对于wcf服务,Json返回readresponse()失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,

  public   interface  IDriverService 
{

[OperationContract]
[WebInvoke(UriTemplate = GetData,Method = POST,RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
List< Availability> GetData(GetDriverRequest GetDriverRequest);
}



< service behaviorConfiguration =   debug name =   CloudServices.DriverService >  
< endpoint address = json binding = webHttpBinding bindingConfiguration = webHttpBindingSettings behaviorConfiguration = RestJSONEndpointBehavior contract = CloudServices.IDriverService />
< / 服务 >





< webHttpBinding> 
< binding name = webHttpBindingSettings openTimeout = 10:00:00
receiveTimeout = 10:00:00 sendTimeout = 10:00:00 maxBufferPoolSize = 2147483647
maxReceivedMessageSize = 2147483647 crossDomainScriptAccessEnabled = true >
< readerQuotas maxDepth = 128 maxStringContentLength = 2147483647
maxArr ayLength = 2147483647 maxBytesPerRead = 2147483647 maxNameTableCharCount = 2147483647 / >
< / binding >
< / webHttpBinding >





< endpointBehaviors> 
< behavior name = RestJSONEndpointBehavior >
< webHttp helpEnabled = true defaultOutgoingResponseFormat = Json />
< / 行为 >
< / endpointBehaviors >





我的要求应该是这样的



< pre lang =C#> http: // localhost:2502 / DriverService.svc / json / GetData?APIKEY = cbe55c45 -0987-4cd4-81e9-73ae18888b9c
内容类型:application / json
{ City Vijayawada GetAction Driversavailabledays }

响应:
[Fiddler] ReadResponse()失败:服务器没有返回 请求的完整回复。服务器返回 0 字节。





我尝试过:



我使用xml响应处理wcf服务。它工作正常。现在我需要为wcf服务更改xml到json响应。我更改了界面中json的web.config设置和请求和响应格式。

下面列出的代码适用于xml但不适用于Json。

请帮帮我解决这个问题

谢谢

解决方案

最后我得到了Json Response。问题在于日期时间。现在它已经解决了

问题:

 DateTime.MinValue未被序列化时区之前的UTC 



解决方案:

 [DataMember(IsRequired =  false  ,EmitDefaultValue =  false )] 



在任何DateTime会员上添加此内容


Hi friends,

public interface IDriverService
   {

       [OperationContract]
       [WebInvoke(UriTemplate = "GetData", Method = "POST", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
       List<Availability> GetData(GetDriverRequest GetDriverRequest);
   }


<service behaviorConfiguration="debug" name="CloudServices.DriverService">
       <endpoint address="json" binding="webHttpBinding" bindingConfiguration="webHttpBindingSettings" behaviorConfiguration="RestJSONEndpointBehavior" contract="CloudServices.IDriverService" />
     </service>



<webHttpBinding>
        <binding name="webHttpBindingSettings" openTimeout="10:00:00"
          receiveTimeout="10:00:00" sendTimeout="10:00:00" maxBufferPoolSize="2147483647"
          maxReceivedMessageSize="2147483647" crossDomainScriptAccessEnabled="true">
          <readerQuotas maxDepth="128" maxStringContentLength="2147483647"
            maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
        </binding>
      </webHttpBinding>



<endpointBehaviors>
        <behavior name="RestJSONEndpointBehavior">
          <webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json"/>
        </behavior>
      </endpointBehaviors>



My request should be like this

http://localhost:2502/DriverService.svc/json/GetData?APIKEY=cbe55c45-0987-4cd4-81e9-73ae18888b9c
Content-type:application/json
{"City":"Vijayawada","GetAction":"Driversavailabledays"}

Response:
[Fiddler] ReadResponse() failed: The server did not return a complete response for this request. Server returned 0 bytes.



What I have tried:

I worked on wcf services with xml response. it's working fine. Now i need to change xml to json response for wcf service. I changed the web.config settings and request and response formats for json in Interface.
the below listed code is working fine for xml but not for Json.
Please help me to fix this issue
Thanks

解决方案

Finally i got Json Response. The problem is with date time. Now it was solved
Issue:

DateTime.MinValue not be serialized in timezones ahead of UTC


Solution :

[DataMember(IsRequired = false, EmitDefaultValue = false)]


Added this on any DateTime Member


这篇关于对于wcf服务,Json返回readresponse()失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆