Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WCF - Define multiple services in a single APP.Config file?

Tags:

wcf

service

Scenario

I have a windows forms application. I want to use two different WCF Services that are in no way connected. HOWEVER, I'm not sure how to go about defining the services in my APP.CONFIG file. From what I have read, it is possible to do what I have done below, but I cannot be sure that the syntax is correct or the tags are all present where necessary and I needed some clarification.

Question.

So is the below the correct way to setup two services in A SINGLE APP.CONFIG FILE? I.E:

<configuration>
    <system.serviceModel>
        <services>
            <service>
                <!--SERVICE ONE-->
                <endpoint>
                </endpoint>
                <binding>
                </binding>
            </service>
            <service>
                <!--SERVICE TWO-->
                <endpoint>
                </endpoint>
                <binding>
                </binding>
            </service>
        </services>
    </system.serviceModel>
</configuration>

CODE

<configuration>
    <system.serviceModel>
        <services>
        <!--SERVICE ONE-->
            <service>
                <endpoint
                    address=""
                    binding="netTcpBinding"
                    bindingConfiguration="tcpServiceEndPoint"
                    contract="ListenerService.IListenerService"
                    name="tcpServiceEndPoint"
                />
                <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>
            </service>
            <!--SERVICE TWO-->
            <service>
                <endpoint
                    address=""
                    binding="netTcpBinding"
                    contract="UploadObjects.IResponseService"
                    bindingConfiguration="TransactedBinding"
                    name="UploadObjects.ResponseService"
                />
                <binding name="TransactedBinding">
                    <security mode="None" />
                </binding>
            </service>
        </services>
    </system.serviceModel>
</configuration>

EDIT

What do the BEHAVIOURS represent? How do they relate to the service definitions?

EDIT 2

Does the Service Name need to be the same as the Binding Name?

like image 377
Goober Avatar asked Apr 06 '10 12:04

Goober


1 Answers

You don't have your config quite right:

<configuration>
  <system.serviceModel>
     <behaviors>
        ... here you define sets of behaviors - behavior configurations
     </behaviors>
     <bindings> 
        ... here you define your binding configurations (parameters for bindings)
     </bindings> 
     <services>
        <service name="Service1"> 
          ... here you define the service endpoint which includes the ABC of WCF:
          ... (A)ddress, (B)inding, (C)ontract
        </service>
        <service name="Service2"> 
          ... here you define the service endpoint which includes the ABC of WCF:
          ... (A)ddress, (B)inding, (C)ontract
        </service>
        ....
      </services>    
  </system.serviceModel>
</configuration>

The services and service endpoints can reference behavior configurations, as well as binding configurations, by specifying the behaviorConfiguration= and bindingConfiguration= settings respectively.

You should definitely have a look at the WCF Configuration Editor tool to give you a hand at configuring your WCF services! It should be available from the Visual Studio "Tools" menu:

alt text

and it looks something like this:

alt text

like image 188
marc_s Avatar answered Oct 19 '22 22:10

marc_s