Despite reading a number of posts eg (This one seems popular) I can't seem to expose my service as multiple endpoints that are compatible with both the SOAP and REST protocol - my problem seems to be with the
Factory="System.ServiceModel.Activation.WebServiceHostFactory"
element in the Service code behind page.
If I leave it out, my SOAP endpoint works grand, but my JSON endpoint is not found. If I put the line in, my REST endpoint sings like bird and the the SOAP endpoint is results in "Endpoint not found" on the Service.svc page.
My operations appear to set up in the standard way eg:
[OperationContract]
[WebGet(UriTemplate = "/GetData", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
string GetData();
And the configuration file
<endpoint address="rest" binding="webHttpBinding" contract=".IMeterService" behaviorConfiguration="REST" />
<endpoint address="soap" binding="wsHttpBinding" contract="IMeterService" bindingConfiguration="secureBasic" />
<behavior name="REST">
<webHttp />
</behavior>
How can I achieve this? Is there a way to set up the REST endpoint without the System.ServiceModel.Activation.WebServiceHostFactory attribute?
Thanks in advance.
If you don't specify any factory in the .svc file, all the endpoints will come from the web.config file - WCF will try to find a
<system.serviceModel / service>
element whosename
attribute matches the fully-qualified name of the service class. If it doesn't find one, then it will add a default endpoint (usingbasicHttpBinding
, unless you changed the default mapping). That appears to be what you're facing. Confirm that the "name" attribute of the<service>
element matches the value of theService
attribute in the .svc file, and you should have the two endpoints working out fine.Another thing you can try to do is to enable tracing in the service (level = Information) to see which endpoints were actually opened on the service. The image below:
The server for this example is nothing major:
The Service.svc doesn't have factory specified:
And the web.config defines two endpoints, which are shown in the traces:
Notice that there's an extra listener shown in the listener, it's the "help page" from WCF (the one which tells, when you browse to it, that the service doesn't have metadata enabled).
You can try either to compare this setup with yours, or start with this simple one, then start adding component from yours until you hit the issue. That will help isolate the problem.
Good luck!