1

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 ?

4

2 回答 2

2

您可以在同一服务中使用 REST 和 SOAP,但在 SOAP 的情况下,将使用 HTTP POST 调用操作。您的合同定义正确。您必须修改配置:

  <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> 
于 2010-09-01T08:40:21.363 回答
-1

我会删除 webget 属性并使用 basichttpbinding。然后您可以使用任何soap 或wcf 客户端访问该服务。

除了 svc 之外,您还可以托管一个 asmx,但这感觉不太好。

问候,

米歇尔

于 2010-09-01T08:11:27.747 回答