【问题标题】:Request Method "DELETE" not calling a method in web service请求方法“DELETE”未调用 Web 服务中的方法
【发布时间】:2014-07-21 18:07:06
【问题描述】:

我需要调用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。这是什么?

【问题讨论】:

  • 根本不可能没有错误。在 android 部分发布更多上下文代码,然后再次检查您的 logcat
  • 我插入代码con.getResponseCode(),返回值401,这是什么?

标签: c# android web-services httpurlconnection


【解决方案1】:

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

我将“删除”更改为“POST”,应用程序运行正常。

谢谢!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-04-01
    相关资源
    最近更新 更多