I have written a service that I would like expose both via rest and soap. Everything I read about WCF 4.0 says that I just need to expose 2 endpoints with differing behavio
How are you hosting your WCF service?? In IIS, you need a virtual directory and a MyService.svc
file somewhere to enable service activation.
If you remove the ServiceRoute for now (to simplify matters), you should be able to reach your SOAP service endpoint at:
http://YourServer:Port/YourVirtualDirectory/YourService.svc/soap
and your REST service should be at
http://YourServer:Port/YourVirtualDirectory/YourService.svc/rest/data/{value}
(where you supply some arbitrary value for {value}
).
What exactly is not working in your case??
You can try and test your SOAP endpoints using the WCF Test Client, while you should be able to hit the REST url in any browser.
This is possible to do in configuration. From msdn forum thread by user Ladislav Mrnka: http://social.msdn.microsoft.com/Forums/en-US/wcf/thread/4e95575f-1097-4190-80dd-7a0f96d73f6e
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="REST">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="iSell.Prospects.ProspectBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="iSell.Prospects.ProspectBehavior" name="iSell.Prospects.ProspectService">
<endpoint address="" behaviorConfiguration="REST" binding="webHttpBinding" contract="iSell.Prospects.ProspectService" />
<endpoint address="soap" binding="basicHttpBinding" contract="iSell.Prospects.ProspectService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
I never found the "right" way to do this in configuration but was able to use the routing engine to accomplish this.
My global asax file now looks like this:
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.Add(new ServiceRoute("my/soap", new ServiceHostFactory(), typeof(MyService)));
RouteTable.Routes.Add(new ServiceRoute("my/rest", new WebServiceHostFactory(), typeof(MyService)));
}
}
and my config like this: (to enable the rest help pages)
<system.serviceModel>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint automaticFormatSelectionEnabled="true" helpEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
I like that this is in line with the asp.net MVC model more and requires little config. Additionally doing it this way allowed me to remove the .svc files from my project entirely which is also a plus IMO.