简体   繁体   English

添加WCF服务引用时,HTTP请求被禁止,客户端身份验证方案“匿名”错误

[英]The HTTP request was forbidden with client authentication scheme 'Anonymous' error, when adding WCF service reference

I am having an issue when trying to add a service reference to my winforms app. 我在尝试向winforms应用程序添加服务引用时遇到问题。 Both the service and the app are in the same solution and the service is using iisexpress with the default iisexpress development certificate installed. 服务和应用程序都在同一个解决方案中,服务使用iisexpress并安装了默认的iisexpress开发证书。 When I try to add the service reference I get the normal dialogs which find the service and then tell me the certificate is not signed by an authority. 当我尝试添加服务引用时,我得到了正常的对话框,找到了服务,然后告诉我证书没有被权威机构签名。 I "Ok" that message but then I get this error. 我“确定”了那条消息,但后来我收到了这个错误。

The HTTP request was forbidden with client authentication scheme 'Anonymous'. 客户端身份验证方案“匿名”禁止HTTP请求。

The web.config for the web service is as follows Web服务的web.config如下所示

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5" />
        <authentication mode="Windows" />
        <identity impersonate="false" />
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="WsHttpBindingConfig">
          <security mode="TransportWithMessageCredential">
            <transport clientCredentialType="Certificate" />
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>

    </bindings>
    <protocolMapping>
        <add binding="wsHttpBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true" />
  </system.webServer>

</configuration>

EDIT---------------- 编辑 - - - - - - - -

I also get the following messagebox pop up after I accept the certificate. 我接受证书后,我也会弹出以下消息框。

"There was an error downloading metadata from this address.Please verify that you have entered a valid address" “从此地址下载元数据时出错。请确认您输入了有效地址”

Also I have found if I change 我也发现如果我改变了

<protocolMapping>
        <add binding="wsHttpsBinding" scheme="https" />
    </protocolMapping>

to

<protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>

Then I can suddenly add the reference. 然后我可以突然添加参考。 Why is this? 为什么是这样? Surely I need it to be wsHttpsBinding? 当然我需要它是wsHttpsBinding?

In your configuration you have <transport clientCredentialType="Certificate" /> , which indicates a signed certificate must be used to authenticate the client. 在您的配置中,您有<transport clientCredentialType="Certificate" /> ,表示必须使用签名证书对客户端进行身份验证。 For that you need to have a properly signed certificate. 为此,您需要具有正确签名的证书。

Try using <transport clientCredentialType="None" /> to circumvent or look at the various options to see which one applies to your use case. 尝试使用<transport clientCredentialType="None" />来规避或查看各种选项,以查看哪一个适用于您的用例。

I have now fixed this issue. 我现在已经解决了这个问题。

I needed to change the following config on the server 我需要在服务器上更改以下配置

<protocolMapping>
        <add binding="wsHttpBinding" scheme="https" />
    </protocolMapping>

to

<protocolMapping>
        <add binding="wsHttpBinding" scheme="https" bindingConfiguration="WsHttpBindingConfig" />
    </protocolMapping> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IIS托管具有SSL安全性的WCF-“ HTTP请求被客户端身份验证方案&#39;Anonymous&#39;禁止”错误 - IIS hosted WCF with SSL security -“The HTTP request was forbidden with client authentication scheme 'Anonymous'” error 客户端身份验证方案“匿名”禁止HTTP请求。 3 - The HTTP request was forbidden with client authentication scheme 'Anonymous'. 3 WCF自托管:匿名身份验证方案禁止使用HTTP请求 - WCF self-hosted: http request forbidden for authentication scheme anonymous 出现403禁止错误。 客户端身份验证方案“匿名”禁止HTTP请求 - Getting 403 Forbidden error. The HTTP request was forbidden with client authentication scheme 'Anonymous' 客户端身份验证方案“匿名”禁止 HTTP 请求。 远程服务器返回错误:(403) Forbidden - The HTTP request was forbidden with client authentication scheme 'Anonymous'. The remote server returned an error: (403) Forbidden 如何添加ClientCeritifcates,HTTP请求被禁止使用客户端身份验证方案&#39;Anonymous&#39; - How to add ClientCeritifcates, The HTTP request was forbidden with client authentication scheme 'Anonymous' 重现问题:客户端身份验证方案“匿名”禁止使用http请求 - Reproduce Issue: The http request was forbidden with client authentication scheme 'anonymous' 如何修复“客户端身份验证方案‘匿名’禁止 HTTP 请求” - How to fix "The HTTP request was forbidden with client authentication scheme 'Anonymous'" BizTalk 发送端口抛出错误 System.Net.WebException:HTTP 请求被禁止使用客户端身份验证方案“匿名” - BizTalk send port throws error System.Net.WebException: The HTTP request was forbidden with client authentication scheme 'Anonymous' WCF-TransportWithMessageCredential使用客户端身份验证方案“匿名”对HTTP请求进行未授权 - WCF-TransportWithMessageCredential The HTTP request is unauthorized with client authentication scheme 'Anonymous'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM