尝试向winforms应用添加服务引用时遇到问题。服务和应用程序都在同一个解决方案中,服务使用iisexpress并安装了默认的iisexpress开发证书。当我尝试添加服务引用时,我得到了正常的对话框,找到了服务,然后告诉我证书没有被权威机构签名。我“确定”了那条消息,但后来我收到了这个错误。
使用客户端身份验证方案禁止HTTP请求 '匿名'。
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 ----------------
我接受证书后,也会弹出以下消息框。
“从此地址下载元数据时出错。请确认您已输入有效地址”
我也发现如果我改变了
<protocolMapping>
<add binding="wsHttpsBinding" scheme="https" />
</protocolMapping>
到
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
然后我可以突然添加引用。为什么是这样?当然我需要它是wsHttpsBinding?
答案 0 :(得分:0)
在您的配置中,您有<transport clientCredentialType="Certificate" />
,表示必须使用签名证书对客户端进行身份验证。为此,您需要有一个正确签名的证书。
尝试使用<transport clientCredentialType="None" />
规避或查看the various options以查看哪一个适用于您的用例。
答案 1 :(得分:0)
我现在已经解决了这个问题。
我需要更改服务器上的以下配置
<protocolMapping>
<add binding="wsHttpBinding" scheme="https" />
</protocolMapping>
到
<protocolMapping>
<add binding="wsHttpBinding" scheme="https" bindingConfiguration="WsHttpBindingConfig" />
</protocolMapping>