I have an WCF service which I am trying to configure so that it exposes 2 endpoints, refering to different functionalities, under different URLs.
What I want to have is Service1, exposing methods A, B, C, and Service2, exposing methods D, E. I want to be able to browse both localhost/WebServiceName/Service1/Service.svc and localhost/WebServiceName/Service2/Service.svc.
Other applications referencing localhost/WebServiceName/Service1/Service.svc should see only the interface containing the methods A, B and C. They should not see anything regarding Service2 interface. And for Service2 likewise.
So far I have defined two interfaces in my WCF service, I_Service1 and I_Service2.
I have added two endpoints in my web.config like so:
<endpoint address="http://localhost/WebServiceName/Service1/" binding="wsHttpBinding" contract="WebServiceName.I_Service1" bindingConfiguration="Binding1" />
<endpoint address="http://localhost/WebServiceName/Service2/" binding="wsHttpBinding" contract="WebServiceName.I_Service2" bindingConfiguration="Binding2" />
The suggestion of using full address in the enpoint comes from here: Multiple endpoints under IIS
But still, I can't browse localhost/WebServiceName/Service1/Service.svc. I receive:
Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.
I can successfully browse localhost/WebServiceName/Service.svc and the wsdl includes methods A, B, C, D, E. But this should be wrong in the behaviour I want.
Is there something that I have missed?
UPDATE: Following this article http://allen-conway-dotnet.blogspot.ro/2011/09/exposing-multiple-binding-types-for.html I created two different contract services for those endpoints. But currently I am seing only Service1 when I browse it. Service2 apparently does not exist (HTTP 404 error related issues appear).
The configuration looks like:
<services>
<service behaviorConfiguration="WebServiceName.ServiceBehavior1" name="WebServiceName.Service1">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
contract="WebServiceName.I_Service1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/WebServiceName/Service1/Service.svc" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="WebServiceName.ServiceBehavior2" name="WebServiceName.Service2">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
contract="WebServiceName.I_Service2" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/WebServiceName/Service2/Service.svc" />
</baseAddresses>
</host>
</service>
</services>
The way I've always done this is as follows: set a single "base address" for the service and specify the endpoint addresses as different text to append onto that base address...
<service name="MyNamespace.MyService">
<endpoint address="FirstEndpointAddress" binding="netTcpBinding"
name="FirstEndpointName"
contract="MyNamespace.FirstEndpointContract" />
<endpoint address="SecondEndpointAddress" binding="netTcpBinding"
name="SecondEndpointName"
contract="MyNamespace.SecondEndpointContract" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8733/MyBaseAddress" />
</baseAddresses>
</host>
</service>
So in your case the base address might be localhost/WebServiceName
and the endpoint address for endpoint 1 might be Service1/Service.svc
. Likewise for endpoint 2 it might be Service2/Service.svc
. I can see that you've followed advice to put the full address in the endpoint address, but all I can say is I've done it this way with success.
For the moment my solution to this problem was incorporating two .svc files in my webservice to separate the two interfaces. Such, I have localhost/WebServiceName/Service1.svc and localhost/WebServiceName/Service2.svc.
With the endpoint configuration
<services>
<service behaviorConfiguration="WebServiceName.ServiceBehavior1" name="WebServiceName.Service1">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
contract="WebServiceName.I_Service1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/WebServiceName/Service1.svc" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="WebServiceName.ServiceBehavior2" name="WebServiceName.Service2">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding2"
contract="WebServiceName.I_Service2" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/WebServiceName/Service1.svc" />
</baseAddresses>
</host>
</service>
</services>
This solution is not necessary the best one (if a client really wants, it can find that this service exposes 2 different interfaces, but I can secure them with different credentials/tokens). But at the moment I will go with it.
I tried to make the thing which you described. All of this succeed. Please do'nt be angry if some of steps are obvious for you. So:
By default I got the following Web.config in Web Application project:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="BasicHttpBinding_IService2" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:3597/Service1.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService1" contract="ServiceReference1.IService1"
name="BasicHttpBinding_IService1" />
<endpoint address="http://localhost:3597/Service2.svc" binding="basicHttpBinding"
bindingConfiguration="BasicHttpBinding_IService2" contract="ServiceReference2.IService2"
name="BasicHttpBinding_IService2" />
</client>
You can try to rebuild WCF project and Update WebReferences.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With