Reputation: 29720
Im trying to combine SOAP and REST under one roof with some modification. 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. 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:
<%@ ServiceHost Language="C#" Debug="true" Service="VLSContentService" CodeBehind="VLSContentService.svc.cs" %>
And the cs(codebehind) file:
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>
Upvotes: 0
Views: 890
Reputation: 6109
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>
Upvotes: 3