gpt4 book ai didi

WCF 端口配置错误

转载 作者:行者123 更新时间:2023-12-04 20:26:41 26 4
gpt4 key购买 nike

我有两个服务,通过配置文件进行配置。他们每个人都监听一个 http 和一个 https 地址。问题是如何配置端口。如果我将 http 端口配置为相同的值并将 https 端口配置为另一个值,则在调试整个项目时,我会在 WCF 服务主机中收到以下错误消息:

Status: Error System.ServiceModel.AddressAlreadyInUseException: HTTP could not register URL https://+:8002/Services/xxxService/ because TCP port 8002 is being used by another application. ---> System.Net.HttpListenerException: The process cannot access the file because it is being used by another process



如果我将四个端口(http 和 https)配置为具有不同的值,并且没有一个 https 值是在 IIS 中配置和认证的 ssl 端口的值,则在服务调用时出现以下异常(但两个服务都在WCF 服务主机):

An error occurred while making the HTTP request to https://localhost:8000/Services/yyyService/. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.



如果我将第一个服务配置为使用 SSL 端口 (443),则仅启动第二个服务(具有“错误”https 端口的服务)。第一个服务的错误信息再次是:

System.ServiceModel.AddressAlreadyInUseException: HTTP could not register URL https://+:443/Services/xxxService/ because TCP port 443 is being used by another application. ---> System.Net.HttpListenerException: The process cannot access the file because it is being used by another process



最重要的是,在调用第二个服务时出现异常:

An error occurred while making the HTTP request to https://localhost/Services/yyyService/. This could be due to the fact that the server certificate is not configured properly with HTTP.SYS in the HTTPS case. This could also be caused by a mismatch of the security binding between the client and the server.



当我将这两个服务配置为使用 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com