接收 GET 和 SOAP 请求的 WCF 方法
我创建了一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在同一服务中使用 REST 和 SOAP,但在使用 SOAP 的情况下,将使用 HTTP POST 调用操作。您的合同定义正确。您必须修改您的配置:
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:
我会删除 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