接收 GET 和 SOAP 请求的 WCF 方法

发布于 2024-09-17 08:49:13 字数 1544 浏览 3 评论 0原文

我创建了一个 WCF 服务,其方法可以使用 WebGET 属性接收 GET 请求,我也希望使用相同的方法接收 Soap 调用(当程序员对 WCF 进行服务引用时,他将能够调用该方法)。

我的界面是:

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

我的配置是:

<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>

我可以使 Web 方法 GetData 成为 HTTP GET 和 SOAP 方法吗?

我需要在配置中添加什么?

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 ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤檠 2024-09-24 08:49:13

您可以在同一服务中使用 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> 

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> 
﹂绝世的画 2024-09-24 08:49:13

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

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

问候,

米歇尔

I would delete the webget attribute and use basichttpbinding. Then you can access the service with any soap or wcf client.

You can also host an asmx besides the svc, but that doesn't feel quiet right.

Regards,

Michel

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文