WCF Service Using Json Bad Request

I cannot let my life figure out what is happening and who I cannot send to the service using json. I tried reading every comment under the sun from Google on issues that I have, but everything is currently leading me into a dead end. Please, help!

I am transferring the postback service to third parties at the callback URL in the message to the service. The third party then returns back to Json back to my wcf service using the return URL. I have no problem with the original message, but they and I cannot get into the callback service. I still tried, but Fiddler returns a 400 error, but I'm not sure why. I need a little more than web links and such to fix this problem. please, help!

Web.config File

<system.serviceModel> <services> <service behaviorConfiguration="serviceBehavior" name="IBVWebService.InstantBankVerificationPostBack"> <endpoint address="http://localhost:64337/InstantBankVerificationPostBack.svc" behaviorConfiguration="web" binding="webHttpBinding" contract="IBVWebService.IInstantBankVerificationPostBack"></endpoint> <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" /> </service> </services> <behaviors> <endpointBehaviors> <behavior name="web"> <webHttp/> </behavior> </endpointBehaviors> <serviceBehaviors> <behavior name="serviceBehavior"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="false" /> </behavior> </serviceBehaviors> </behaviors> 

Web interface

  [OperationContract] [WebInvoke( Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json)] void PostBack(String json); 

Test client

  WebClient client = new WebClient(); client.Headers["Content-type"] = "application/json"; client.Encoding = System.Text.Encoding.UTF8; string jsonInput = "{'data':'testvalue'}"; client.UploadString("http://localhost:64337/InstantBankVerificationPostBack.svc/PostBack", jsonInput); 

current trace log. Tracelog

+5
source share
2 answers

I replicated your script using a simple wcf service with your configurations and a simple test client:

FOS

 [OperationContract] [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.WrappedRequest, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)] void PostBack(String json); 

Customer:

 string jsonInput = "{\"json\":\"testvalue\"}"; using (var client = new WebClient()) { client.Headers["Content-type"] = "application/json"; client.Encoding = System.Text.Encoding.UTF8; client.UploadString("http://localhost:51175/Service1.svc/PostBack", "POST", jsonInput); } 

In the client, make sure that you match the signature of your WCF method, that is, the object you expect is called json, so when you call the method from your client, send json: 'value'

Also, consider using the using statement for the web client to ensure that it is deleted after use.

+5
source

The name of your method parameter is "json", so the input JSON parameter should look like this:

 string jsonInput = "{'json':'testvalue'}"; 
0
source

All Articles