【问题标题】:WCF REST Error 401.3 in PUT and DELETE methods but not in GET and POSTWCF REST 错误 401.3 在 PUT 和 DELETE 方法中,但在 GET 和 POST 中没有
【发布时间】: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


    【解决方案1】:

    我们解决了这个问题。这就像还没有定义 ssl 身份验证方法一样愚蠢。如果您添加<authentication mode="None" />,只是为了测试,所有方法都可以正常工作。

    我们将很快添加身份验证方法,但我很想知道为什么 get 和 post 不关心设置或不关心身份验证方法,而 put 和 delete 关心。

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,添加到 web.config 中解决了

      <system.web>
          <authentication mode="None" />
        </system.web>
      

      我不知道发生了什么,我什么也没做,有人知道为什么吗?也许是网络服务器的实现。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-05-23
        • 2013-08-26
        • 1970-01-01
        • 1970-01-01
        • 2015-01-25
        • 2023-03-09
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多