tags:

views:

263

answers:

3

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?

A: 

Combine them together.

      <system.serviceModel>
          <behaviors>
            <serviceBehaviors>
              <behavior name="Service1Bevhavior">

              </behavior>
              <behavior name="Service2Bevhavior"/>
            </serviceBehaviors>
          </behaviors>


          <services>
            <!--SERVICE ONE-->
            <service name="Service1">
              <endpoint address=""
              binding="netTcpBinding"
              bindingConfiguration="tcpServiceEndPoint"
              contract="ListenerService.IListenerService"
              name="tcpServiceEndPoint" />

            </service>
            <service name="Service2">
              <endpoint address=""
                                  binding="netTcpBinding"
                                  contract="UploadObjects.IResponseService"
                                  bindingConfiguration="TransactedBinding"
                                  name="UploadObjects.ResponseService"/>
            </service>
          </services>
          <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>
            <netTcpBinding>
              <binding name="TransactedBinding">
                <security mode="None" />
              </binding>
            </netTcpBinding>

          </bindings>
        </system.serviceModel>
Nix
A: 

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

marc_s
A: 

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

The Service Name should be the contract implementation class. If you want to use a binding configuration, the binding config name should be the same as the bindingConfiguration setting of the endpoint.

    <configuration>

<system.serviceModel>

<services>

<!--SERVICE ONE-->
<service name="ListenerService.ListenerServiceImplementation" >
<endpoint address=""
          binding="netTcpBinding"
          bindingConfiguration="tcpServiceEndPoint"
          contract="ListenerService.IListenerService" />
<!--SERVICE TWO-->
<service name="UploadObjects.ResponseServiceImplementation" />
<endpoint address=""
          binding="netTcpBinding"
          bindingConfiguration="TransactedBinding"
          contract="UploadObjects.IResponseService" />
</services>
<bindings>

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

      <binding name="TransactedBinding">
        <security mode="None" />
      </binding>
</bindings>

</system.serviceModel>


</configuration>
Erup
You can use the MSDN resources too, if needed: http://msdn.microsoft.com/en-us/library/ms735119%28v=VS.85%29.aspx
Erup