[英]Is it possible to set up a WCF service as REST & SOAP this way?
Im trying to combine SOAP and REST under one roof with some modification. 我试图通过一些修改将SOAP和REST结合在一起。 But I dont know whether its possbile. 但我不知道它的可能性。 My code is below, it used to work when REST only but since I tried to add the extra web service as SOAP (using configuration) it doesnt work. 我的代码在下面,它过去仅在REST时有效,但是由于我尝试将额外的Web服务添加为SOAP(使用配置),因此它不起作用。 Not sure how to configure it... 不确定如何配置...
I have the interfaces: 我有接口:
[ServiceContract]
public interface IVLSContentServiceREST
{
[OperationContract]
[WebGet]
string EchoWithGet(string s);
[OperationContract]
[WebInvoke]
string EchoWithPost(string s);
}
[ServiceContract]
public interface IVLSContentServiceSOAP
{
[OperationContract]
[WebGet]
string EchoWithGet(string s);
[OperationContract]
[WebInvoke]
string EchoWithPost(string s);
}
Then I have a file called VLSContentService.svc with this: 然后,我有了一个名为VLSContentService.svc的文件:
<%@ ServiceHost Language="C#" Debug="true" Service="VLSContentService" CodeBehind="VLSContentService.svc.cs" %>
And the cs(codebehind) file: 和cs(codebehind)文件:
public class VLSContentService : IVLSContentServiceSOAP, IVLSContentServiceREST
{
string IVLSContentServiceSOAP.EchoWithGet(string s)
{
return "You said " + s;
}
string IVLSContentServiceSOAP.EchoWithPost(string s)
{
return "You said " + s;
}
string IVLSContentServiceREST.EchoWithGet(string s)
{
return "You said " + s;
}
string IVLSContentServiceREST.EchoWithPost(string s)
{
return "You said " + s;
}
}
And the configuration: 并配置:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<!---Add the service-->
<services>
<service behaviorConfiguration="VLSContentServiceBehaviour" name="VLSContentService">
<endpoint address="rest" behaviorConfiguration="VLSContentServiceEndpointBehaviour" binding="webHttpBinding" contract="IVLSContentServiceREST"/>
<endpoint address="soap" behaviorConfiguration="VLSContentServiceEndpointBehaviour" binding="basicHttpBinding" contract="IVLSContentServiceSOAP"/>
</service>
</services>
<!---Add the behaviours-->
<behaviors>
<serviceBehaviors>
<behavior name="VLSContentServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<!---Add the behaviours-->
<endpointBehaviors>
<behavior name="VLSContentServiceEndpointBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
You don't need two versions of the contract - just host the same contract at two endpoints using different bindings 您不需要两个版本的合同-只需使用不同的绑定在两个端点上托管同一合同
<services>
<service behaviorConfiguration="VLSContentServiceBehaviour" name="VLSContentService">
<endpoint address="rest" behaviorConfiguration="VLSContentServiceEndpointBehaviour" binding="webHttpBinding" contract="IVLSContentService"/>
<endpoint address="soap" behaviorConfiguration="VLSContentServiceEndpointBehaviour" binding="basicHttpBinding" contract="IVLSContentService"/>
</service>
</services>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.