Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing JQGrid in conjunction with WCF Web Services
    text
    copied!<p>I am trying to obtain the data for JQGrid from a WCF Web service that is running from within my ASP.NET 2.0 WebForms application. The problem is that the WCF Web service expects the data to be formatted as a JSON string, and JQGrid is performing an HTTP Post and passing it as Content-Type: application/x-www-form-urlencoded. </p> <p>Although there appears to be several options for the format of data returned to JQGrid (it accepts JSON, XML, and others), there doesn't seem to be a way to alter the way it passes inputs to the web service.</p> <p>So I'm trying to figure out how to tweak the WCF service so that it will accept </p> <pre><code>Content-Type: application/x-www-form-urlencoded </code></pre> <p>rather than</p> <pre><code>Content-Type:"application/json; charset=utf-8" </code></pre> <p>When I did a test using JQuery to send an Ajax request using url encoding (shown here):</p> <pre><code>$.ajax({ type: "POST", url: "../Services/DocLookups.svc/DoWork", data: 'FirstName=Howard&amp;LastName=Pinsley', contentType: "Content-Type: application/x-www-form-urlencoded", dataType: "json", success: function(msg) { alert(msg.d); } }); </code></pre> <p>the call fails. Using Fiddler to inspect the traffic, I found the error as returned by the server:</p> <pre><code>{"ExceptionDetail":{"HelpLink":null,"InnerException":null,"Message": "The incoming message has an unexpected message format 'Raw'. The expected message formats for the operation are 'Xml', 'Json'. This can be because a WebContentTypeMapper has not been configured on the binding. See the documentation of WebContentTypeMapper for more details."... </code></pre> <p>Note that this code DOES work due to the difference in encoding</p> <pre><code>$.ajax({ type: "POST", url: "../Services/DocLookups.svc/DoWork", data: '{"FirstName":"Howard", "LastName":"Pinsley"}', contentType: "application/json; charset=utf-8", dataType: "json", success: function(msg) { alert(msg.d); } }); </code></pre> <p>On the server, the service looks like:</p> <pre><code>[ServiceContract(Namespace = "")] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] [ServiceBehavior(IncludeExceptionDetailInFaults = true)] public class DocLookups { // Add [WebGet] attribute to use HTTP GET [OperationContract] public string DoWork(string FirstName, string LastName) { return "Your name is " + LastName + ", " + FirstName; } } </code></pre> <p>and my web.config contains:</p> <pre><code>&lt;system.serviceModel&gt; &lt;behaviors&gt; &lt;endpointBehaviors&gt; &lt;behavior name="DocLookupsAspNetAjaxBehavior"&gt; &lt;enableWebScript /&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;/behaviors&gt; &lt;serviceHostingEnvironment aspNetCompatibilityEnabled="true" /&gt; &lt;services&gt; &lt;service name="DocLookups"&gt; &lt;endpoint address="" behaviorConfiguration="DocLookupsAspNetAjaxBehavior" binding="webHttpBinding" contract="DocLookups" /&gt; &lt;/service&gt; &lt;/services&gt; &lt;/system.serviceModel&gt; </code></pre> <p>Thanks for any help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload