WCF端口配置错误

时间:2009-07-06 11:09:54

标签: wcf configuration

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

  

状态:错误   System.ServiceModel.AddressAlreadyInUseException:   HTTP无法注册URL   https://+:8002/Services/xxxService/   因为正在使用TCP端口8002   另一个应用。 --->   System.Net.HttpListenerException:The   进程无法访问该文件,因为   它被另一个进程使用

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

  

制作时出错   HTTP请求   https://localhost:8000/Services/yyyService/。   这可能是因为这个事实   未配置服务器证书   适当地使用HTTPS中的HTTP.SYS   案件。这也可能是由a引起的   安全绑定不匹配   在客户端和服务器之间。

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

  

System.ServiceModel.AddressAlreadyInUseException:   HTTP无法注册URL   https://+:443/Services/xxxService/   因为正在使用TCP端口443   另一个应用。 --->   System.Net.HttpListenerException:The   进程无法访问该文件,因为   它被另一个进程使用

最重要的是,我在调用第二个服务时遇到异常:

  

制作时出错   HTTP请求   https://localhost/Services/yyyService/。   这可能是因为这个事实   未配置服务器证书   适当地使用HTTPS中的HTTP.SYS   案件。这也可能是由a引起的   安全绑定不匹配   在客户端和服务器之间。

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

我一直试图将这件事情运行两天,所以任何一个人都会受到赞赏。

PS。在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>

2 个答案:

答案 0 :(得分:1)

您的错误“服务器证书未正确配置”可能与您使用“localhost”访问该服务有关。您的证书可能使用其他内容,例如计算机名称。

尝试将地址更改为计算机名称。

您还需要在配置中指定使用https端点的传输安全性。

答案 1 :(得分:0)

您是否为端口配置了SSL证书? (如果该端口可用于您的服务) 您是否尝试在IIS中托管服务?

http://msdn.microsoft.com/en-us/library/ms733791.aspx