Click here to Skip to main content
15,881,938 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends,
C#
public interface IDriverService
   {

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

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


C#
<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>


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


My request should be like this

C#
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
Posted
Updated 11-Feb-16 1:10am
v3
Comments
Beginner Luck 11-Feb-16 4:38am    
u cannot return null but can return ""
.net333 11-Feb-16 4:46am    
this is my Response:
[Fiddler] Read Response() failed: The server did not return a complete response for this request. Server returned 0 bytes.
working fine for Xml but for Json Getting this error

1 solution

Finally i got Json Response. The problem is with date time. Now it was solved
Issue:
C#
DateTime.MinValue not be serialized in timezones ahead of UTC

Solution :
C#
[DataMember(IsRequired = false, EmitDefaultValue = false)]

Added this on any DateTime Member
 
Share this answer
 
Comments
Abdul Subhan Khan(MA$K) 26-Apr-16 3:41am    
Thanks RK ... its really helpfull

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900