Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This post has already a very good answer by "Community wiki" and I also recommend to look at Rick Strahl's Web Blog, there are many good posts about WCF Rest like <a href="http://west-wind.com/weblog/posts/896411.aspx" rel="noreferrer">this</a>.</p> <p>I used both to get this kind of MyService-service... Then I can use the REST-interface from jQuery or SOAP from Java.</p> <p>This is from my Web.Config:</p> <pre><code>&lt;system.serviceModel&gt; &lt;services&gt; &lt;service name="MyService" behaviorConfiguration="MyServiceBehavior"&gt; &lt;endpoint name="rest" address="" binding="webHttpBinding" contract="MyService" behaviorConfiguration="restBehavior"/&gt; &lt;endpoint name="mex" address="mex" binding="mexHttpBinding" contract="MyService"/&gt; &lt;endpoint name="soap" address="soap" binding="basicHttpBinding" contract="MyService"/&gt; &lt;/service&gt; &lt;/services&gt; &lt;behaviors&gt; &lt;serviceBehaviors&gt; &lt;behavior name="MyServiceBehavior"&gt; &lt;serviceMetadata httpGetEnabled="true"/&gt; &lt;serviceDebug includeExceptionDetailInFaults="true" /&gt; &lt;/behavior&gt; &lt;/serviceBehaviors&gt; &lt;endpointBehaviors&gt; &lt;behavior name="restBehavior"&gt; &lt;webHttp/&gt; &lt;/behavior&gt; &lt;/endpointBehaviors&gt; &lt;/behaviors&gt; &lt;/system.serviceModel&gt; </code></pre> <p>And this is my service-class (.svc-codebehind, no interfaces required):</p> <pre><code> /// &lt;summary&gt; MyService documentation here ;) &lt;/summary&gt; [ServiceContract(Name = "MyService", Namespace = "http://myservice/", SessionMode = SessionMode.NotAllowed)] //[ServiceKnownType(typeof (IList&lt;MyDataContractTypes&gt;))] [ServiceBehavior(Name = "MyService", Namespace = "http://myservice/")] public class MyService { [OperationContract(Name = "MyResource1")] [WebGet(ResponseFormat = WebMessageFormat.Xml, UriTemplate = "MyXmlResource/{key}")] public string MyResource1(string key) { return "Test: " + key; } [OperationContract(Name = "MyResource2")] [WebGet(ResponseFormat = WebMessageFormat.Json, UriTemplate = "MyJsonResource/{key}")] public string MyResource2(string key) { return "Test: " + key; } } </code></pre> <p>Actually I use only Json or Xml but those both are here for a demo purpose. Those are GET-requests to get data. To insert data I would use method with attributes:</p> <pre><code>[OperationContract(Name = "MyResourceSave")] [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, UriTemplate = "MyJsonResource")] public string MyResourceSave(string thing){ //... </code></pre>
 

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