请求方法“DELETE”不在Web服务中调用方法

时间:2014-07-21 18:07:07

标签: c# android web-services httpurlconnection

我需要调用方法cancel,但系统不会调用该方法,也不会显示错误。

url = new URL("http://localhost/api/Service.svc/Method/cancel");
con = (HttpURLConnection) url.openConnection();
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
con.setRequestProperty("Authorization", "Basic " + Base64.encodeToString("user:password".getBytes(), Base64.NO_WRAP ));
con.setRequestMethod("DELETE");
con.connect();

在我的服务器C#中:

[OperationContract]
[WebInvoke(Method = "DELETE", BodyStyle = WebMessageBodyStyle.Bare, 
RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, 
UriTemplate = "/cancel")]
void Cancel();

缺少什么?

更新:   我插入代码con.getResponseCode()并返回值401.这是什么?

1 个答案:

答案 0 :(得分:0)

我解决了这个问题。插入代码con.getResponseCode()后,系统返回410(未授权)。寻找这个,找到了真正的原因:结构Web服务WCF不支持动词"删除"。

我改变了#34;删除"到" POST"并且应用程序正确运行。

谢谢!

相关问题