WCF endpoint address, default still available after specifying an address - wcf

These are my endpoints
endpoint name="rest" address="" binding="webHttpBinding"
behaviorConfiguration="poxBehavior"
contract="IActionService"
endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
which makes the service available at /here
when I change the address to [say] 'rest'
endpoint name="rest" address="rest" binding="webHttpBinding"
behaviorConfiguration="poxBehavior"
contract="IActionService"
endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
the service is then available at /rest/here.
which makes sense, but it is also available from the original address of /here
I thought that the original address would not exist as I have set the address to 'rest'.
What am I doing wrong or misunderstanding?
Cheers

What defines your base address of /here ? Do you have a <host> section with <baseAddress> entries in it?
What do you mean by "still available" from the original address? Requests going there still return valid results?? Have you reset IIS after this config change??

Related

One WCF service listening to multiple addresses (config only)

I have an existing Windows service (so no IIS) which hosts a WCF-service.
At this moment it is listening one address: http://xxx/service.svc.
And now I want it to ALSO listen to a second address: http://yyy/service.svc.
I can only modify the configuration, not the sources. The service is running under .NET Framework 4.5.2.
My configuration:
<services>
<service behaviorConfiguration="All" name="MyNamespace.MyService">
<endpoint address="" binding="basicHttpBinding" bindingConfiguration="myBindingConfig" contract="MyNamespace.IMyService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://xxx/service.svc"/>
</baseAddresses>
</host>
</service>
</services>
What I have tried so far:
Added an extra base address. Then I get an exception: This collection already contains an address with scheme http.
Duplicated the service-element and modify the base address. Exception: A child element named 'service' with same key already exists at the same configuration scope.
If I change the name of both services: Service 'MyNamespace.MyService' has zero application (non-infrastructure) endpoints.
If have read about and tried serviceHostingEnvironment (as suggested in WCF service startup error "This collection already contains an address with scheme http") but only adding that snippet in, does not help. Maybe that is a half step forward, but then I need the second half of that solution.

Each contract has to be hosted in one ServiceHost?

I want to expose two contracts in my server. The app config file of the service is:
<services>
<service name="Interface1Service">
<endpoint address="" binding ="customBinding" contract="Interface1"
bindingName="binding_Interface1" bindingConfiguration="CustomBinding_Interface1" name="epInterface1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Interface1/" />
</baseAddresses>
</host>
</service>
<service name="Interface2Service">
<endpoint address="" binding ="customBinding" contract="Interface2"
bindingName="binding_Interface2" bindingConfiguration="CustomBinding_Interface1"
name="epInterface2Service">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Interface2/" />
</baseAddresses>
</host>
</service>
</services>
And in my console application to host the service I have:
ServiceHost miHost = new ServiceHost(typeof(Interface1Service));
miHost.Open();
ServiceHost miHost2 = new ServiceHost(typeof(Interface2Service));
miHost2.Open();
Console.ReadKey();
miHost.Close();
miHost2.Close();
My doubt if this is the correct way to expose the two services or there is any way to use only one serviceHost to do that.
Because I have seen that is very common to have many contracts for related operations, such as one interface for modify product, other to modify persons, other for orders... etc.
Thank you so much.
..is any way to use only one serviceHost to do that?
It is certainly possible to expose multiple service contracts in a single hosting container. You simply need to create a class which implements all the service interfaces:
public class MyService : Interface1, Interface2
{
// implement your operations here...
}
// then create service host:
var miHost = new ServiceHost(typeof(MyService));
My doubt if this is the correct way to expose the two services..
Even though WCF lets you do this, whether you should do this is another question.
If the operations exposed by the services were deemed different enough that they were placed into separate service contracts, then this is a clear signal that these are in fact different services, and should therefore be treated as such.
Having a common concrete implementation for all these different services introduces coupling and should probably not be done.

Can I use wsHttpBinding along with webHttpBinding in WCF service?

I have a custom username-password WCF service that needs to be called by Windows client (Winforms application) as well as by Web client (html/aspx page). I have two endpoints declarations in web.config but, to make it work, I have to comment one of them and so, only the client type, associated with that un-commented endpoint, can access the service. If I un-commment that, and comment the other one, other client can access it. I can't keep both of them and so I can't access it with both types of clients.
<service behaviorConfiguration="Behavior1" name="BeST.Service.Service">
<endpoint address="" binding="webHttpBinding" contract="BeST.Service.IService" behaviorConfiguration="EndpBehavior"></endpoint>
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
contract="BeST.Service.IService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/" />
</baseAddresses>
</host>
</service>
just as the code shows, I need to use both endpoints (above two endpoints) if I want to make this service work for both clients OR, if there's another way to have it done, please help!
The problem is that you are giving the same address to both endpoints. Try to give another relative address to one of your endpoints and it should work.
<service behaviorConfiguration="Behavior1" name="BeST.Service.Service">
<endpoint address="web" binding="webHttpBinding" contract="BeST.Service.IService" behaviorConfiguration="EndpBehavior"></endpoint>
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="Binding1"
contract="BeST.Service.IService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/" />
</baseAddresses>
</host>
</service>

How to start host & start service with two endpoint with WcfSvcHost.exe

i have one service with two endpoint. one endpoint is for wsdual binding and another for tcp binding. when i start my wcf service with wcfsvchost.exe like
WcfSvcHost.exe /service:"C:
\Users\TRIDIP\Documents\Visual Studio 2010\Projects\BBAChatService\BBAChatService\bin
\BBAChatService.dll" /config:"C:\Users\TRIDIP\documents\visual studio 2010\Projects
\BBAChatService\BBAChatService\Web.config"
then my service was started but it is showing only one mex endpoint. it should show two mex endpoint because i have two endpoint declared in web.config file. here is my config file entry.
<service name="BBAChatService.ChatService" behaviorConfiguration="BBAChatService.ChatServiceBehavior" >
<host>
<baseAddresses>
<add baseAddress ="http://localhost:8732/ChatService.svc/"/>
<add baseAddress ="net.tcp://localhost:7998/ChatService/"/>
</baseAddresses>
</host>
<endpoint name="dual_bind"
address="dual"
binding="wsDualHttpBinding"
bindingConfiguration="WSDualHttpBinding_IChatService"
contract="BBAChatService.IChatService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint name="tcp_bind"
address="tcp"
binding="netTcpBinding"
bindingConfiguration="tcpBinding"
contract="BBAChatService.IChatService">
</endpoint>
<endpoint address="net.tcp://localhost:7996/ChatService/mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
is there anything i miss in config file. please guide me what i need to do as a result wcfsvchost will show two different endpoint for my service. thanks

How to expose multiple MEX endpoints from a WCF service?

I have an existing web service and I want it to expose 2 MEX endpoints, one exposed through whatever binding it already has and one through Service Bus Relay Binding. I know how to expose a metadata endpoint from the article here: MSDN Link for Exposing MEX through SB
I need to know how to expose multiple MEX endpoints especially for the scenario that I have and moreover if my approach is correct.
It should be this way
<endpoint address ="basicHttp" binding="basicHttpBinding" contract="WCFTest.ISomeContract"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint name="RelayEndpoint"... />
<endpoint name="MexEndpoint" contract="IMetadataExchange" binding="netTcpRelayBinding" bindingConfiguration="default" address="mex" />