Wednesday, April 28, 2010

Setting up WCF Configuration using the Service Configuration Editor

1. Create a new service using basicHttpBinding

Service type: Typically the name of the class that will be implementing the Service contract (interface).
Contract: Name of the interface that represents the service contract that this service is using.
Communication mode: select HTTP if your service will be running within IIS as a website.
Interoperability: Basic web services interoperability (for BasicHttpBinding)
Address: (blank)

Once the wizard completes, click on the “Services” node under Configuration and then click on the first node under EndPoints (typically - (Empty Name)).
Provide a name for the endpoint. (basic)
Click on the “Services” node. Under the services pane, click “Click to create” for Binding Configuration.
Change the name to BasicBinding.

Add WSDL
Go to the node “Service behaviors” under advanced.
Click “New service behavior configuration” and name it BasicServiceBehavior
Click Add, and select “serviceMetadata”
Double click the added item “serviceMetaData”.
Set HttpGetEnabled to true.
Click on the “Service” node under “Services” (this is the service that you have created)
Set the behavior configuration to the one you just created.

This is what your configuration will look like

<behaviors>
   <serviceBehaviors>
    <behavior name="BasicServiceBehavior">
     <serviceMetadata httpGetEnabled="true" />
    </behavior>
   </serviceBehaviors>
  </behaviors>
  <bindings>
   <basicHttpBinding>
    <binding name="BasicBinding" />
   </basicHttpBinding>
  </bindings>
  <services>
   <service behaviorConfiguration="BasicServiceBehavior" name="Service">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicBinding"
     name="basic" contract="IService" />
   </service>
  </services>

2. Create an endpoint that uses wsHttpBinding

First – create your binding.
Right click on “Bindings” node and select new binding configuration.
Name it “wsInsecureBinding”
On the security tab (right pane), set Mode to none, EstablishSecurityContext to false, MessageClientCredentialType to None, NegotiateServiceCredential to false, TransportClientCredentialType to None.
image 
Now create the endpoint:

Right click on the EndPoints node (under Services->YourServiceName) and select new endpoint. Name it “wsInsecure”
Set the address to /wsInsecure
Set the binding to wsHttpBinding
Set the bindingConfiguration to the one you just created “wsInsecureBinding”
Set the contract to the name of the interface that is your service contract.
image

The binding configuration will now look like this (changes highlighted in bold):

<behaviors>
   <serviceBehaviors>
    <behavior name="BasicServiceBehavior">
     <serviceMetadata httpGetEnabled="true" />
    </behavior>
   </serviceBehaviors>
  </behaviors>
  <bindings>
   <basicHttpBinding>
    <binding name="BasicBinding" />
   </basicHttpBinding>
   <wsHttpBinding>
    <binding name="wsInsecureBinding">
     <security mode="None">
      <transport clientCredentialType="None" />
      <message clientCredentialType="None" negotiateServiceCredential="false"
       establishSecurityContext="false" />
     </security>
    </binding>
   </wsHttpBinding>
  </bindings>
  <services>
   <service behaviorConfiguration="BasicServiceBehavior" name="Service">
    <endpoint address="" binding="basicHttpBinding" bindingConfiguration="BasicBinding"
     name="basic" contract="IService" />
   <endpoint address="/wsInsecure" binding="wsHttpBinding" bindingConfiguration="wsInsecureBinding"
     name="wsInsecureBinding" contract="IService" />
   </service>
  </services>

No comments: