Thomas
Thomas

Reputation: 34208

Regarding WCF service url & Mex Endpoint usage

i am learning wcf so often questions comes to my mind.recently i developed a small calculator wcf service. i had three project one has service contract and another has wcf service with main class from where i self host the service. in app.config file i gave my endpoint address net.tcp://localhost:5555/Calculator i always thought that i have to give my service class name at the end of service url. in my apps my service url looks like above and Calculator is my service class name.

just few days ago i was browsing a wcf code and i saw that there service class name was chatsrv but service url would look like net.tcp://localhost:5555/chat

i like to know that can i give any name to my service at the end?

1) if so then how self host code can understand at which url service need to start ?

2) if i set false for <serviceMetadata httpGetEnabled="false"/> then how other client consuming my service because i have set httpGetEnabled="false" and self host the service but from other .net project i could consume that service by channel factory and as add reference? so tell me what people need to set httpGetEnabled="true" if false works fine?

whatever i know that if httpGetEnabled="false" then mex endpoint will not expose to other client and hence forth no other client may not be able to add reference to their project of my service reference. i am new so not good about the service internal. if possible please discuss it in detail.

3) why mex endpoint is required when client can instantiate & call service function through channel factory without mex endpoint then why & when mex endpoint would require?

thanks

UPDATE

1) i like to know that can i give any url as endpoint address ? i have given this net.tcp://localhost:5555/chat as my endpoint address and it works but if i give the endpoint address like net.tcp://localhost:5555/Mychat then does it work?

i like to know what is the convention of giving endpoint address url?

2) now regarding mex endpoint. in my service config file i disable mex like but still i saw any client can add reference like net.tcp://localhost:5555/chat/mex how it is possible ?

when mex is disable then mex point should not be expose or accessible before client...am i right?

please guide me. thanks

Upvotes: 0

Views: 3039

Answers (2)

Nirav Mehta
Nirav Mehta

Reputation: 7073

Comment out below line because it'll be added automatically while configuring the proxy in your configuration file where you defined endpoints of the service.

<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />

If you want to check, Right click on service proxy where you added service proxy, and select "Configure Service Reference" and you'll notice /mex is added in URL of the service at last

Upvotes: 0

Brian
Brian

Reputation: 3713

I'll try to answer some of your questions:

1) When you configure your service, you have to configure the endpoint URL, either with the popular config file or in code like this:

 Dim URL as string = "http://ServerName:port/SomeClass/SomeFunction"
 Dim ServiceHost As New ServiceHost(GetType(YourImplementationClass), URL) 
 Dim ServiceHostEndPoint As EndpointAddress = New EndpointAddressURL(URL) 
 ServiceHost.AddServiceEndpoint(GetType(iYourImplementationClass), binding, ServiceHostEndPoint.ToString)
 ServiceHost.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpsBinding(), "mex")
 ServiceHost.Open()

2) You can give your clients the URL and xsl directly, but exposing your endpoint with Mex is easier for everyone. Also, if you make changes, they can re-reference your mex metadata and automatically update their interfaces.

3) mex isn't required if clients are configuring the endpoints themselves using the channel factory, it's just easier using mex. Just typing your endpoint URL into a browser will generate most of what they need to connect to your web service.

Hope that helps.

Upvotes: 3

Related Questions