wcfsoapgetwebget

WCF Method that receive GET AND SOAP Requests


i created a WCf service with a method that can receive GET requests using WebGET attribute, i want the same method to receive Soap calls too (that when the programmer does a Service reference to the WCF, he will be able to call the method).

my interface is:

[ServiceContract] 
public interface IService1 
{ 
  [OperationContract] 
  [WebGet(UriTemplate = "GetData?value={value}")] 
  string GetData(int value); 
} 

My configuration is:

<configuration>
 <system.web>
  <compilation debug="true" targetFramework="4.0" />
 </system.web>
 <system.serviceModel>
  <behaviors>
   <serviceBehaviors>    
    <behavior name="MyServiceBehavior">
     <serviceMetadata httpGetEnabled="true"/>
     <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior> 
   </serviceBehaviors>
   <endpointBehaviors>
    <behavior name="WebBehavior">
     <webHttp />
    </behavior>
   </endpointBehaviors>
  </behaviors>
  <services>
   <service name="WCFTestingGetService.Service1" behaviorConfiguration="MyServiceBehavior" >
    <endpoint address="" binding="webHttpBinding" contract="WCFTestingGetService.IService1" behaviorConfiguration="WebBehavior"></endpoint>
   </service>
  </services>
  <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
 </system.serviceModel>
 <system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
 </system.webServer>
</configuration>

Can i make teh web method GetData a HTTP GET and SOAP method ?

what do i need to add to the Config ?


Solution

  • You can use REST and SOAP in the same service but in the case of SOAP the operation will be called with HTTP POST. Your contract is defined correctly. You have to modify your configuration:

      <services> 
       <service name="WCFTestingGetService.Service1" behaviorConfiguration="MyServiceBehavior" > 
        <endpoint address="" binding="webHttpBinding" contract="WCFTestingGetService.IService1" behaviorConfiguration="WebBehavior"/>
        <endpoint address="soap" binding="basicHttpBinding" contract="WCFTestingGetService.IService1"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
       </service> 
      </services>