c# - 更改证书后的 WCF SOAP 安全协商
问题描述
将自签名证书“localhost”(DNS=localhost)更改为“Cloudflare Origin Certificate”(dns=mydomain.com)后,出现以下错误:
SOAP security negotiation with 'http://localhost:8000/MyService.svc' for target 'http://localhost:8000/MyService.svc' failed. See inner exception for more details.
内部异常:
Either the client credential was invalid or there was an error collecting the client credentials by the SSPI.
我注意到的是,在我启动客户端后,我得到了输入凭据的窗口。不知道为什么。
我到底做了什么:
- 在 IIS 中生成的证书请求
- 在 CloudFlare 上完成的证书
- 使用 CloudFlare Root CA 将收到的密钥粘贴到文本文件中
- 在 IIS 中完成的证书(个人、本地机器)
- 在 MMC 中添加到 Trusted Publishers CloudFlare Root CA (LocalMachine)
- 对于 WCF 网站,将 SSL 证书更改为 CloudFlare
- 客户端值从“localhost”更改为“mydomain.com”
- 服务器值从“localhost”更改为“mydomain.com”
- 将 findValue 更改为
WCF web.config
<system.serviceModel>
<client />
<behaviors>
<serviceBehaviors>
<behavior name="authBehavior">
<serviceAuthorization principalPermissionMode="UseWindowsGroups">
<authorizationPolicies>
<add policyType="WCF.Common.AuthorizationPolicy, WCF" />
</authorizationPolicies>
</serviceAuthorization>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="WCF.Common.IdentityValidator, WCF" />
<serviceCertificate findValue="CloudFlare Origin Certificate" storeLocation="LocalMachine" x509FindType="FindBySubjectName" storeName="My" />
</serviceCredentials>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="svcBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpsBinding>
<binding name="basicHttpsEndpointBinding" maxReceivedMessageSize="1073741824" maxBufferSize="1073741824" maxBufferPoolSize="1073741824">
<readerQuotas maxDepth="32" maxArrayLength="1073741824" maxStringContentLength="1073741824" />
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpsBinding>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding"></binding>
</wsHttpBinding>
</bindings>
<services>
<service name="WCF.MyService" behaviorConfiguration="svcBehavior">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpEndpointBinding" contract="WCF.IMyService">
<identity>
<dns value="mydomain.com" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
客户端 app.config
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MessageAndUserName">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
<binding name="WSHttpBinding_IMyService" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8777/MyService.svc"
binding="wsHttpBinding" contract="WCF.IMyService"
name="WSHttpBinding_IMyService">
<identity>
<dns value="mydomain.com" />
</identity>
</endpoint>
</client>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
我在我的 WCF 中托管了其他服务,并且我在 Client 中托管了一些服务,但它们都不需要。
我在 WCF 和客户端之间使用 wsHttpBindings。我能做些什么来摆脱这个错误?
使用 wsHttpBinding 等的目的是什么...:仅允许此客户端与 MyService 进行通信.. 不允许其他任何人。客户端应用程序将在域中的多台计算机上运行。你建议使用不同的方法吗?
感谢您的任何想法!
编辑:有错误的计算机未在域中运行。既不适用于域中的计算机:/
EDIT2:安全模式传输 WCF web.config 绑定:
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
<security mode="Transport">
<message clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
客户端配置绑定:
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMyService">
<security mode="Transport">
<message clientCredentialType="None" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://localhost:8001/MyService.svc"
binding="wsHttpBinding" contract="WCF.IMyService"
name="WSHttpBinding_IMyService">
<identity>
<dns value="mydomain.com" />
</identity>
</endpoint>
</client>
解决方案
这里有一些资源可供查看,以帮助确定 NetTcpBinding 是否适合您,这听起来像是因为您在内部使用 Web 服务。
当 WCF 服务及其客户端位于 Intranet 基础结构中时,NetTcpBinding是最好的。由于它只支持 TCP 协议而不支持 HTTP,因此无法通过 Internet 访问服务。
这是一种安全绑定,用于在 Intranet 计算机中发送二进制编码的 SOAP 消息。它支持可靠性、事务性和安全性。如果您在 IIS 中使用 netTcpBinding 并托管 WCF 服务,您需要在系统和 IIS 上进行一些设置,本文将帮助您进行所需的设置。
解决相关问题的一些提示:
- 双击 MMC 中的证书,它会在证书信息标题下显示任何错误消息吗?
- 您是否可以在浏览器中从客户端浏览服务?
- 证书是否在 IIS 中分配
- 你有正确的绑定吗
- 客户端是否使用与服务主机相同的绑定?
- 您的端点是否引用了正确的绑定和服务行为
有关 NetTcpBinding 的其他有用信息:
推荐阅读
- google-chrome - Chrome DevTools 不显示孩子
- javascript - 即使刷新页面,如何让 HTML 输入标签记住其中的数据?
- sql - 查询仅显示字段中的最近日期,而所有 SELECTS 都不在 GROUP
- php - 为什么在尝试使用 sprintf 时出现“未找到基表或视图”?
- python - 根据其他列值重命名列
- r - 在 R 图上的文本中使用多行时,符号和上标之间的空格
- c# - 在 C# 中创建自定义 UIAutomation 属性
- python - 如何将 python distutils.core 函数调用“扩展”转换为 gcc 命令
- react-native - 我什么时候真的需要 redux 来反应原生?
- razor - 使用 Core 2.1 和 Razor 页面,如何搭建模型而不使用 ID 字段