Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat is the best way in WebMatrix to query WCF services?
    primarykey
    data
    text
    <p>I have an ASP.Net project using the Razor view engine which currently queries various databases directly with WebMatrix.Data.Database.Open.</p> <p>I'm trying to migrate all direct database access to Web Services using WCF so that I get consistent business logic. In doing this, I have also enabled the WCF service to be "httpGetEnabled". This allows me to use Excel Macros to query the same web service.</p> <p>My question is, what is the best way to query these web services from a Razor/WebMatrix page?</p> <p>Should I JSON enable my WCF service and use the WebMatrix JSON helper? Or should I be using JQuery to get the xml?</p> <p>I would assume the former would be the best way, but how do I JSON enable my WCF service? I remember seeing a video that allowed me to specify an additional query parameter to the WCF request to get JSON, but I can't find it again.</p> <p>Any thoughts or pointers in the right direction would be greatly appreciated.</p> <p>Kind regards.</p> <hr> <p>Edit:</p> <p>I've recently seen this on Stack Overflow : <a href="https://stackoverflow.com/questions/5074603/client-side-binding-using-by-converting-the-wcf-services-to-json">Client Side Binding using by Converting the WCF Services to JSON</a> </p> <p>On following this, I went to the MSDN article referred to around WebHttpBehavior. I have since added "automaticFormatSelectionEnabled=true" to the webHttp element in Web.config. In addition, I added the following code which then allowed me to specify "format=json" as a query parameter:</p> <pre><code>string formatQueryStringValue = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"]; if (!string.IsNullOrEmpty(formatQueryStringValue)) { if (formatQueryStringValue.Equals("xml", System.StringComparison.OrdinalIgnoreCase)) { WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Xml; } else if (formatQueryStringValue.Equals("json", System.StringComparison.OrdinalIgnoreCase)) { WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json; } } </code></pre> <p>I now just need to work out how to use the WebMatrix JSON helper to get the results... Will update when I get some more information.</p> <hr> <p>Edit 2 </p> <p>Hmm, I don't think that helped... Now I can get JSON from the webservice, but the JSON web helper only seems to help if you have some JSON data already. I'm just not sure how to get that JSON data which I can then use the JSON Helper to convert it (decode) into a class.</p> <p>So I guess my question now is, how do I get JSON data and then bridge that to WebMatrix/Razor for use in a WebGrid?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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