【问题标题】:WCF Multiple Service Configuration IssueWCF 多服务配置问题
【发布时间】:2011-02-04 17:35:57
【问题描述】:

场景

忽略某些设置可能错误、不一致或根本不存在的事实!

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

错误

类型初始化异常

代码

<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>

【问题讨论】:

  • 如果能得到实际的错误就好了……
  • 您如何加密和签署您的消息。我希望看到某处提到 x509

标签: wcf configuration


【解决方案1】:

几个观察:

  1. 您的&lt;client&gt; 端点没有地址:

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

    您希望您的客户端代码如何知道连接到哪里?需要在任意客户端&lt;endpoint&gt;指定完整的WCF服务地址

  2. 您的&lt;service&gt; 端点也缺少地址 - 您要么需要在此处指定完整地址,要么必须在服务中定义基地址!两者之一必须存在:

    <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>
    

另外,从你的问题来看,当你收到错误时,不清楚你想做什么:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-02
    • 2011-04-15
    • 1970-01-01
    • 2011-09-19
    • 2020-01-09
    • 2010-09-08
    • 1970-01-01
    相关资源
    最近更新 更多