How to expose multiple MEX endpoints from a WCF service? - wcf

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" />

Related

How to log requests to mex endpoints

I've got a WCF service with exposed mex endpoints in it. I need to implement additional loging for it
<endpoint address="MEX"
binding="mexHttpBinding"
contract="IMetadataExchange" />
Is there any way to log users request for mex endpoints?

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.

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 Consume WCF Service in Service Reference if it has multiple Endpoint with name

I have very specific question..
If i create one WCF Service and it has multiple endpoints with the name how can i access that using browser ?
Also How can i access that in my client application via Add Service Reference ?
like my config code:
<services>
<service name="MultipleEndpoint.SampleService" behaviorConfiguration="MultipleEndpoint.SampleService">
<host>
<baseAddresses>
<add baseAddress="http://localhost:55052/SampleService.svc"/>
</baseAddresses>
</host>
<endpoint address="/basic" binding="basicHttpBinding" contract="MultipleEndpoint.ISampleService" bindingConfiguration="basicBinding" >
</endpoint>
<endpoint address="/wsHttp" binding="wsHttpBinding" contract="MultipleEndpoint.ISampleService" bindingConfiguration="wsBinding" >
</endpoint>
<endpoint address="/webHttp" binding="webHttpBinding" contract="MultipleEndpoint.ISampleService" behaviorConfiguration="REST">
</endpoint>
</service>
</services>
Now, when i tried to access that using
http://localhost:55052/SampleService.svc/basic or
http://localhost:55052/SampleService.svc/wsHttp
it gives me page/ resource not found IE Standard Error Message...
Same time i like to know how would i add this type of url as a service reference in my client application ?
Those service addresses are different and they are not strictly needs to be brow-sable, means you can't browse a service for an endpoint like http://localhost:55052/SampleService.svc/basic. Those addresses are used to distinguish endpoints in communication.
If you see the wsdl of the service all the addresses of those endpoints are specified there.
If you create the proxy of the service through "Add Service Reference" all the endpoints are created in the configuration separately like..
<client>
<endpoint address="http://localhost:54671/Service1.svc/basic"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="ServiceReference1.IService1" name="BasicHttpBinding_IService1" />
<endpoint address="http://localhost:54671/Service1.svc/ws" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
name="WSHttpBinding_IService1">
</endpoint>
...
</client>
Say if you want to talk to the service using the basic http endpoint then you can create the proxy for that by passing the corresponding endpoint configuration name in the ctor.
Ex.
// this will uses the basic http endpoint.
Service1Client client = new Service1Client("BasicHttpBinding_IService1");

WCF endpoint address, default still available after specifying an address

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??