我有两个服务,通过配置文件进行配置。他们每个人都监听一个 http 和一个 https 地址。问题是如何配置端口。如果我将 http 端口配置为相同的值并将 https 端口配置为另一个值,则在调试整个项目时,我会在 WCF 服务主机中收到以下错误消息:
如果我将四个端口(http 和 https)配置为具有不同的值,并且没有一个 https 值是在 IIS 中配置和认证的 ssl 端口的值,则在服务调用时出现以下异常(但两个服务都在WCF 服务主机):
如果我将第一个服务配置为使用 SSL 端口 (443),则仅启动第二个服务(具有“错误”https 端口的服务)。第一个服务的错误信息再次是:
最重要的是,在调用第二个服务时出现异常:
当我将这两个服务配置为使用 443 进行 https 时,嗯……然后什么都没有开始。我得到了各种奇怪的异常——clientcredentials 是只读的,握手遇到了意外的数据包格式,关于远程地址等。
我在 web.config 中配置了两个地址,如下所示:
<baseAddresses>
<add baseAddress="http://localhost:port1/Services/xxxService/" />
<add baseAddress="https://localhost:port2/Services/xxxService/" />
</baseAddresses>
[...]
<baseAddresses>
<add baseAddress="http://localhost:port3/Services/yyyService/" />
<add baseAddress="https://localhost:port4/Services/yyyService/" />
</baseAddresses>
我已经尝试运行这个东西两天了,所以任何帮助都会受到赞赏。
附注。在 Visual Studio 中,我将 IIS 配置为开发服务器,而不是内置的 Visual Studio Web 开发服务器。
编辑:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
<services>
<service name="namespace.xxxService"
behaviorConfiguration="default">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/Services/xxxService/" />
<add baseAddress="https://localhost:8001/Services/xxxService/" />
</baseAddresses>
</host>
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="defaultWsHttpBinding"
contract="namespace.IxxxService" />
<endpoint address="mex/"
binding="mexHttpBinding"
contract="IMetadataExchange"
bindingConfiguration="" />
</service>
<service name="namespace.yyyService" behaviorConfiguration="default">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8003/Services/yyyService/" />
<add baseAddress="https://localhost:8004/Services/yyyService/" />
</baseAddresses>
</host>
<endpoint address=""
binding="wsHttpBinding"
bindingConfiguration="defaultWsHttpBinding"
contract="namespace.IyyyService" />
<endpoint address="mex/"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<client>
<endpoint address="https://localhost:8001/Services/xxxService/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IxxxService"
contract="namespace.IxxxService" name="WSHttpBinding_IxxxService" />
<endpoint address="https://localhost:8001/Services/yyyService/"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IyyyService"
contract="namespace.IyyyService" name="WSHttpBinding_IyyyService" />
</client>
<behaviors>
<serviceBehaviors>
<behavior name="default">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="MembershipProvider"
membershipProviderName="SqlMembershipProvider" />
</serviceCredentials>
<serviceAuthorization principalPermissionMode="UseAspNetRoles"
roleProviderName="SqlRoleProvider" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="defaultWsHttpBinding">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
<transport clientCredentialType="None" />
</security>
</binding>
<binding name="WSHttpBinding_IyyyService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false" >
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
<binding name="WSHttpBinding_IxxxService" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" negotiateServiceCredential="true"
algorithmSuite="Default" establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
最佳答案
您的错误“服务器证书配置不正确”可能与您使用“localhost”访问服务有关。您的证书可能使用其他内容,例如机器名称。
尝试将地址更改为机器名称。
您还需要在配置中指定对 https 端点使用传输安全性。
关于WCF 端口配置错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1086478/