Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>EDIT - Updated in response to your answer:</p> <p>URL is "<a href="http://localhost/test/Test.svc/MethodName" rel="nofollow noreferrer">http://localhost/test/Test.svc/MethodName</a>"<br> postData is the data you want to pass as a parameter.</p> <p>In your case, it looks like you're trying to pass a type. Remember this is being posted in a URL. Break the values of the type into parameters.</p> <p>Example: "<a href="http://localhost/test/Test.svc/Create?id=123456&amp;stringValue=newSampleItem" rel="nofollow noreferrer">http://localhost/test/Test.svc/Create?id=123456&amp;stringValue=newSampleItem</a>"</p> <p>You'll need to change the Operation Contract to accept an int and a string instead of a SampleItem.</p> <pre><code> [WebInvoke(UriTemplate = "Create?id={x}&amp;stringValue={y}", Method = "POST"), OperationContract] public SampleItem Create(int id, string stringValue) { // Create and return the Sample Item. } </code></pre> <p>Let me know how it goes.</p> <p>Patrick.</p> <p>Hi Alex, This is what I use to post to a Restful service... </p> <pre><code>// Create the request WebRequest request; request = WebRequest.Create(url + postData); request.Method = "POST"; byte[] byteArray = Encoding.UTF8.GetBytes(postData); request.ContentType = "application/x-www-form-urlencoded"; request.ContentLength = byteArray.Length; // Get the request stream. Stream dataStream = request.GetRequestStream(); // Write the data to the request stream. dataStream.Write(byteArray, 0, byteArray.Length); // Close the Stream object. dataStream.Close(); // Process the response Stream responseStream; responseStream = request.GetResponse().GetResponseStream(); StreamReader objReader = new StreamReader(responseStream); StringBuilder sb = new StringBuilder(); string sLine = ""; int i = 0; while (sLine != null) { i++; sLine = objReader.ReadLine(); sb.Append(sLine); } responseStream.Close(); string responseXML = sb.ToString() </code></pre> <p>Good Luck,</p> <p>Patrick</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