WCF多服务配置问题

时间:2010-04-06 08:55:05

标签: wcf configuration

方案

忽略某些设置可能错误且不一致或只是不存在的事实!

当我尝试将这两个单独的WCF服务配置放入同一个APP.CONFIG文件时,为什么程序无法编译?一个是由我自己写的,另一个是由朋友写的,但我无法编译应用程序。我错过了什么?

错误

类型初始化异常

CODE

<configuration>
<system.serviceModel>

  <!--START Service 1 CONFIGURATION-->
  <bindings>
    <netTcpBinding>
      <binding name="tcpServiceEndPoint" closeTimeout="00:01:00"
       openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
       transactionFlow="false" transferMode="Buffered" transactionProtocol="OleTransactions"
       hostNameComparisonMode="StrongWildcard" listenBacklog="10" maxBufferPoolSize="524288"
       maxBufferSize="65536" maxConnections="10" maxReceivedMessageSize="65536">
        <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
         maxBytesPerRead="4096" maxNameTableCharCount="16384" />
        <reliableSession ordered="true" inactivityTimeout="00:05:00"
         enabled="true" />
        <security mode="None">
          <transport clientCredentialType="Windows" protectionLevel="EncryptAndSign" />
          <message clientCredentialType="Windows" />
        </security>
      </binding>
    </netTcpBinding>
  </bindings>

  <client>
    <endpoint address=""
     binding="netTcpBinding" bindingConfiguration="tcpServiceEndPoint"
     contract="ListenerService.IListenerService"
     name="tcpServiceEndPoint" />
  </client>
  <!--END Service 1 CONFIGURATION-->


 <!--START Service 2 CONFIGURATION-->
  <services>
    <service name="UploadObjects.ResponseService">
      <!-- Define NetMsmqEndpoint -->
      <endpoint address=""
              binding="netTcpBinding"
              contract="UploadObjects.IResponseService"
              bindingConfiguration="TransactedBinding"/>
     </service>
    </services>
    <bindings>
    <netTcpBinding>
        <binding name="TransactedBinding">
        <security mode="None" />
       </binding>
      </netTcpBinding>
    </bindings>
    <!--END Service 2 CONFIGURATION-->

   </system.serviceModel>
  </configuration>

1 个答案:

答案 0 :(得分:0)

有几点意见:

  1. 您的<client>端点没有地址:

    <client>
        <endpoint address=""
                  binding="netTcpBinding" 
                  bindingConfiguration="tcpServiceEndPoint"
                  contract="ListenerService.IListenerService"
                  name="tcpServiceEndPoint" />
    

    您如何期望您的客户端代码知道连接到哪里?您需要在任何客户端<endpoint>

  2. 中指定完整的WCF服务地址
  3. 您的<service>端点也缺少地址 - 您需要在此处指定完整地址,或者您必须在服务中定义基地址!其中一个必须存在:

    <services>
       <service name="UploadObjects.ResponseService">
          <endpoint address="net.tcp://YourServer:5455/YourServiceAddress"
                    binding="netTcpBinding"
                    contract="UploadObjects.IResponseService"
                    bindingConfiguration="TransactedBinding"/>
       </service>
    

    或:

    <services>
       <service name="UploadObjects.ResponseService">
          <endpoint address=""
                    binding="netTcpBinding"
                    contract="UploadObjects.IResponseService"
                    bindingConfiguration="TransactedBinding"/>
          <host>
             <baseAddresses>
                <add baseAddress="net.tcp://YourServer:5455/YourServiceAddress" />
             </baseAddresses>
          </host>
       </service>
    
  4. 此外,根据您的问题,当您收到错误时,您还不清楚自己要做什么:

    • 您是否正在尝试启动托管该服务的服务主机?控制台应用程序,或IIS?
    • 您是否尝试将客户端连接到正在运行的服务?