2

I am new to WCF. My question is how to pass a long JSON( here I am converting a data table into JSON string) string as parameter for WCF method?

Here is my code:

[OperationContract] [WebInvoke(Method = "GET",ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.WrappedRequest, UriTemplate = "initiateConnection/{jsonData}/{sessionId}")] 
void testMethod(string jsonData, string sessionId); 
public void testMethod(string jsonData, String sessionId) { } 

When I call the testMethod with jsonData string which very long, it is showing

Invalid URI: The Uri string is too long

So in this case should I pass the JSON result using POST method? If yes then how to pass it?

abarisone
  • 3,707
  • 11
  • 35
  • 54
amarb
  • 21
  • 2

2 Answers2

0

A WCF binding has a property called maxReceivedMessageSize, which defaults to something fairly small. You need to increase it to something sufficiently large to handle your JSON string.

You can also configure WCF to output some trace information in both the client and server ends, this will help you identify what is going wrong with your requests, since WCF is prone to hiding the actual exceptions message due to a new exception raised in the internal exception handler.

<system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="System.ServiceModel"
              switchValue="Information, ActivityTracing"
              propagateActivity="true">
        <listeners>
          <add name="sdt"
              type="System.Diagnostics.XmlWriterTraceListener"
              initializeData= "SdrConfigExample.e2e" />
        </listeners>
      </source>
    </sources>
  </system.diagnostics>
Grubsnik
  • 918
  • 9
  • 25
0

If very long is more than 2000 characters, consider this information:

What is the maximum length of a URL in different browsers?

You might change to pack your json data in the content (URI itself it part of the HTTP header). But you should change to HTTP method POST or PUT for that.

Community
  • 1
  • 1
ZoolWay
  • 5,411
  • 6
  • 42
  • 76