简体   繁体   中英

WCF Multiple Service Configuration Issue

Scenario

Ignoring that fact that some of the settings might be wrong and inconsistent or just not there!.

Why does the program fail to compile when I try and put these 2 separate configurations for WCF Services into the same APP.CONFIG file? One was writen by myself and another by a friend, yet I cannot get the application to compile. What have I missed?

ERROR

Type Initialization Exception

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>

A couple of observations:

  1. Your <client> endpoint has no address:

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

    How do you expect your client code to know where to connect to?? You need to specify a full WCF service address in any client <endpoint>

  2. Your <service> endpoint also is lacking an address - you either need to specify a full address here, or than you have to have a base address defined in your service! One of the two must be present:

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

    or:

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

Also, from your question, it's not clear what you're trying to do when you get the error:

  • are you trying to start up a service host that hosts the service? A console app, or IIS?
  • are you trying to connect a client side to a running service?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM