none
Add soap endpoint to WCF REST Service Application.

    Question

  •  

    I've created a project using the "WCF Rest Service Application" template.

    My ServiceContract for the service is like this:

    Snippet

      [ServiceContract]
      public interface IProspectService
      {
        [OperationContract]
        [WebInvoke(Method = "GET", UriTemplate = "SearchProspects/?fname={firstName}&lname={lastName}")]
        Prospects SearchProspects(string firstName, string lastName);
        [OperationContract]
        [WebInvoke(Method = "GET", UriTemplate = "Prospect/{phone}")]
        Prospect GetProspect(string phone);
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "Prospect/{phone}")]
        void CreateProspect(string phone, Prospect prospect);
      }

    Now i've implemented the interface and everything works great.  What i want to do now is expose a soap endpoint to use the same class i've implemented.

    So what I've done is I've added the following in the web.config

    Snippet

      <services>
       <service behaviorConfiguration="Prospects.ProspectBehavior" name="Prospects.ProspectService">
        <host>
         <baseAddresses>
          <add baseAddress="http://localhost:12762/Prospects/ProspectService.svc" />
         </baseAddresses>
        </host>
        <endpoint address="" binding="basicHttpBinding" contract="Prospects.IProspectService"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
       </service>
      </services>
    
      <behaviors>
       <serviceBehaviors>
        <behavior name="Prospects.ProspectBehavior">
         <!-- To avoid disclosing metadata information, 
         set the value below to false and remove the metadata endpoint above before deployment -->
         <serviceMetadata httpGetEnabled="True"/>
         <!-- To receive exception details in faults for debugging purposes, 
         set the value below to true. Set to false before deployment 
         to avoid disclosing exception information -->
         <serviceDebug includeExceptionDetailInFaults="False"/>
        </behavior>
       </serviceBehaviors>
      </behaviors>

    Well this works but in doing this the rest endpoint no longer works (IE reports status code 400).  I'm thinking the routing is no longer working. 

    Routing:

    Snippet

        private void RegisterRoutes()
        {
          RouteTable.Routes.Add(new ServiceRoute("Prospects", new WebServiceHostFactory(), typeof(Prospects.ProspectService)));
        }

    What am i doing wrong here?  Thanks!

    • Edited by A.Carter Thursday, July 01, 2010 6:51 PM Formatting errors
    Thursday, July 01, 2010 6:48 PM

Answers

  • Hello,

    you also have to add your REST endpoint:

      <system.serviceModel>
        <behaviors>
          <endpointBehaviors>
            <behavior name="REST">
              <webHttp />
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="iSell.Prospects.ProspectBehavior">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <services>
          <service behaviorConfiguration="iSell.Prospects.ProspectBehavior" name="iSell.Prospects.ProspectService">
            <endpoint address="" behaviorConfiguration="REST" binding="webHttpBinding" contract="iSell.Prospects.ProspectService" />
            <endpoint address="soap" binding="basicHttpBinding" contract="iSell.Prospects.ProspectService" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>
      </system.serviceModel>

    Now your service provides 3 endpoints. Default endpoint is for REST /soap endpoint for SOAP and /mex endpoint for Metadata.

    Best regards,
    Ladislav

    • Marked as answer by A.Carter Thursday, July 01, 2010 8:55 PM
    Thursday, July 01, 2010 7:33 PM

All replies

  • Hello,

    you also have to add your REST endpoint:

      <system.serviceModel>
        <behaviors>
          <endpointBehaviors>
            <behavior name="REST">
              <webHttp />
            </behavior>
          </endpointBehaviors>
          <serviceBehaviors>
            <behavior name="iSell.Prospects.ProspectBehavior">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="false" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
        <services>
          <service behaviorConfiguration="iSell.Prospects.ProspectBehavior" name="iSell.Prospects.ProspectService">
            <endpoint address="" behaviorConfiguration="REST" binding="webHttpBinding" contract="iSell.Prospects.ProspectService" />
            <endpoint address="soap" binding="basicHttpBinding" contract="iSell.Prospects.ProspectService" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
          </service>
        </services>
      </system.serviceModel>

    Now your service provides 3 endpoints. Default endpoint is for REST /soap endpoint for SOAP and /mex endpoint for Metadata.

    Best regards,
    Ladislav

    • Marked as answer by A.Carter Thursday, July 01, 2010 8:55 PM
    Thursday, July 01, 2010 7:33 PM
  • Thanks a lot!  That worked perfectly.  I thought i wouldn't be required to add the rest endpoint since it was working without it (before i added the service in the web.config). 

    Just to make sure i understand clearly:

    - RouteTable.Routes.Add must be creating a new service if one (of the same type) doesn't exist in the web.config.  That's why it worked when i first created the template.

    - After i added the web.config information, the RouteTable must have been trying use the same service that was specified in the web.config.  And since there was no webHttpBinding endpoint exposed, the route failed.

    - And now, after i added the webHttpBinding, the Routing Module took the endpoint created in the web.config and routed it accordingly.

    Is that pretty much correct?

    Thursday, July 01, 2010 9:07 PM
  • Hello,

    I hope so. Routing and default configuration were added in WCF 4.0 and I hope they integrate with previous functionality.

    Best regards,
    Ladislav

    Thursday, July 01, 2010 9:32 PM
  • I have mine setup exactly same but when i try to deploy it in https:// i get 400 errors. works fine in local developer maching while using CASINI

    Here is my ServiceModel section

     

    <system.serviceModel>
      <bindings>
       <basicHttpBinding>
         <binding name ="customBinding0">
         <security mode="Transport">
          <transport/>
         </security>
        </binding>
       </basicHttpBinding>
      </bindings>  
      <services>
       <service behaviorConfiguration="RaterDataServiceBehavior"
        name="RaterDataService.PAService">
        <endpoint address=""
         behaviorConfiguration="webHttp" binding="webHttpBinding" name="webHttpBinding_RaterDataService"
         contract="RaterDataService.IPAService" />
        <endpoint address="soap" binding="basicHttpBinding" bindingConfiguration="customBinding0" contract="RaterDataService.IPAService"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
       </service>
      </services>
      <behaviors>
       <endpointBehaviors>
        <behavior name="webHttp">
         <webHttp/>
        </behavior>
       </endpointBehaviors>
       <serviceBehaviors>
        <behavior name="RaterDataServiceBehavior">
         <serviceMetadata httpGetEnabled="True" />
         <serviceDebug includeExceptionDetailInFaults="True" />
        </behavior>
       </serviceBehaviors>
      </behaviors>
      <serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false" />
     </system.serviceModel>
    

    In local same thing without bindingConfiguration="customBinding0" works fine. Please help

    Monday, August 08, 2011 4:33 PM