【发布时间】:2014-05-02 18:36:19
【问题描述】:
我要疯了。我在带有 IIS 8 的 Windows Server 2012 中托管了一个 WCF Web 服务。连接是通过 ssl 进行的,我有一个自签名证书,但没关系,因为它是供内部使用的。
我创建了一个 GET 方法和一个 POST 方法。两者都可以从 fiddler 和我们的私有 android 应用程序完美运行。现在我的伙伴创建了 PUT 和 DELETE 方法,并且它们的 http 响应都是 401。所有四种方法都位于同一个服务文件中。我检查了服务器日志,子状态是 3。
我已经调查了 401.3 并且我看到的所有案例场景都是所有方法都失败了,因为错误表明您无权访问该资源。
现在,我怎么能访问一种资源来达到一种方法,但不能访问同一个资源来达到另一种方法?
界面如下:
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate = "Date",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedRequest)]
string GetCurrentDate();
[OperationContract]
[WebInvoke(UriTemplate = "AddPlayer",
Method = "POST",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
Result Insert(Player newPlayer);
[OperationContract]
[WebInvoke(UriTemplate = "UpdatePlayer",
Method = "PUT",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
Result Update(Player updatePlayer);
[OperationContract]
[WebInvoke(UriTemplate = "DeletePlayer/{accountId}",
Method = "DELETE",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
Result Delete(string accountId);
}
这是我在 Fiddler 中尝试的 PUT 和 DELETE 请求:
PUT (service url)/UpdatePlayer HTTP/1.1
User-Agent: Fiddler
Host: (host)
Content-Type: application/json
{"account":"MrFoo", "nick":"", "isOnline":"1", "lat":"", "long":"",
"latHome":"", "longHome":""}
-------------------------------------
DELETE (service url)/DeletePlayer/MrFoo HTTP/1.1
User-Agent: Fiddler
Host: (host)
Content-Type: text/html
更新:this is the thread 解决方案是向用户授予权限,我就是这样做的。
【问题讨论】:
标签: wcf rest ssl iis-8 http-status-code-401