Here is how I try to call the DELETE method from my WCF service:
string tmpUrl1 = "http://localhost:1234/MyService.svc/EndPoint/MyMethod";
WebRequest request1 = WebRequest.Create(tmpUrl1);
request1.Method = "DELETE";
byte[] byteArray1 = Encoding.UTF8.GetBytes("{\"idName\":" + newIdName + "}");
request1.ContentType = "application/json";
request1.ContentLength = byteArray1.Length;
Stream dataStream1 = request1.GetRequestStream();
dataStream1.Write(byteArray1, 0, byteArray1.Length);
dataStream1.Close();
WebResponse response1 = request1.GetResponse();
But I get error 400.
Here is the method’s name in the wcf:
[OperationContract]
[WebInvoke(
Method = "DELETE",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/MyMethod/{deleteRP}/",
BodyStyle = WebMessageBodyStyle.Bare
)]
MyClass MyMethod(string deleteRP);
Where am I making a mistake?
Try enabling Tracing on your service and inspect the trace log for the actual error. Also your url address should have something like
rather than
“http://localhost:1234/MyService.svc/EndPoint/MyMethod”
UPDATE:
Now replace the following line
with