wcfwcf-bindingwcf-4

WCF 4 and multiple endpoint bindings


I am yrying to have the same contract and service to be exposed as both basicHttpBinding and webHttpBinding to be able to do a POST call. somehow it's NEVER seeing the endpoint for webHttpBinding when I look at the wsdl. What I am doing wrong?

<system.serviceModel>
<services>
  <service name="MyService">
    <endpoint address =""
              binding="basicHttpBinding"
              name="EndpointBasic"
              contract="IMyService"/>

    <endpoint address ="PostMethod"
              binding="webHttpBinding"
              name="EndpointJson"
              contract="IMyService"/>
    <host>
      <baseAddresses>
        <add baseAddress ="http://localhost/WebsiteName/MyService.svc"/>
      </baseAddresses>
    </host>
  </service>
</services>
<bindings>
  <basicHttpBinding>
    <binding name="basicBinding" />
  </basicHttpBinding>
  <webHttpBinding>
    <binding name="Postbinding"
             maxBufferSize="65536"
             maxReceivedMessageSize="2000000000"
             transferMode="Streamed">
    </binding>
  </webHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="">
      <serviceMetadata httpGetEnabled="true" />
      <serviceDebug includeExceptionDetailInFaults="true" />
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="JsonBehavior">
      <webHttp defaultOutgoingResponseFormat="Json" />
    </behavior>
  </endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

Thanks!


Solution

  • I have the following service element entry which works for both SOAP and REST:

    <service name="XMLService.RestAndSoapService" behaviorConfiguration="default">
            <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" bindingConfiguration="RestBinding" name="SampleService" contract="XMLService.IRestAndSoapService" />
            <endpoint address="soap" binding="basicHttpBinding" bindingConfiguration="noSecurity" contract="XMLService.IRestAndSoapService" />
          </service>
    

    Points to note in your config:

    1. In your service element your contract and service name are not fully qualified. Make sure that they are fully qualified ie. includes the namespace along with the interface.

    2. You have not specified the bindingConfiguration as "Postbinding" for webHttpEndpoint and "basicBinding" for basicHttpBinding endpoint

    So with the above changes your config might look as shown below:

    <service name="namespace.MyService">
            <endpoint address =""
                      bindingConfiguration="basicBinding"
                      binding="basicHttpBinding"
                      name="EndpointBasic"
                      contract="namespace.IMyService"/>
    
            <endpoint address ="PostMethod"
                      bindingConfiguration="Postbinding"
                      binding="webHttpBinding"
                      name="EndpointJson"
                      contract="namespace.IMyService"/>
            <host>
              <baseAddresses>
                <add baseAddress ="http://localhost/WebsiteName/MyService.svc"/>
              </baseAddresses>
            </host>
          </service>