Tried Code:
var request = WebRequest.Create("http://localhost/RestfulTutorialService/Service.svc/Post");
request.Method = "PUT";
request.ContentType = "application/json";
using (var writer = new StreamWriter(request.GetRequestStream()))
{
var serializer = new JavaScriptSerializer();
var payload = serializer.Serialize(objBlogPost);
writer.Write(payload);
}
var response = (HttpWebResponse)request.GetResponse();
var responseCode = response.StatusCode;
错误:远程服务器返回错误:(405)Method Not Allowed。
我的服务是一项宁静的服务。以下是被调用的方法。
[OperationContract]
[WebInvoke(Method = "PUT", UriTemplate = "/Post", RequestFormat = WebMessageFormat.Json)]
void UpdateBlogPost(BlogPost post);