Hi All, How can I define endpoints with MEX endpoint in app.config file and what I need to run my application then . I have one service contract called IXMLService and I am using WsHttpBinding . Please give me an example . After creating app.config , how can I start the service ?
+2
A:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="YourNamespace.XMLService" behaviorConfiguration="MetadataBehavior">
<!-- Use the host element only if your service is self-hosted (not using IIS) -->
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/service"/>
</baseAddresses>
</host>
<endpoint address=""
binding="wsHttpBinding"
contract="YourNamespace.IXMLService"/>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
UPDATE: To start the service you could write the following console application to host it (by adding the previous app.config):
class Program
{
static void Main(string[] args)
{
using (var host = new System.ServiceModel.ServiceHost(typeof(XMLService)))
{
host.Open();
Console.WriteLine("Service started. Press Enter to stop");
Console.ReadLine();
}
}
}
Darin Dimitrov
2009-07-07 05:54:31
This probably won't work - the MEX endpoint doesn't have a full, complete address, and there's no "baseAddresses" defined......
marc_s
2009-07-07 06:01:39
@marc_s, you're correct, I've assumed IIS. I modified my post accordingly.
Darin Dimitrov
2009-07-07 06:02:42
thanx Darin , just one more question , after creating this app.config file , how will i start the service do i need to do something else , actually i created the app.config file and created a client but when i wana add service reference it says that there is no endpoint on this address...
Praveen
2009-07-07 06:25:26
thank you very much Darin , everything is working perfectaly..
Praveen
2009-07-07 07:15:55
A:
Darin's answer is almost there - you need to either specify FULL complete addresses for both your service and your mex endpoint(s), or you need to add a base address:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="XMLService" behaviorConfiguration="MetadataBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8888/"/>
</baseAddresses>
</host>
<endpoint address="MyService"
binding="wsHttpBinding"
contract="IXMLService"/>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
</system.serviceModel>
Your service would be on http://localhost:8888/MyService, and your MEX data on http://localhost:8888/mex
If you prefer, you can also specify the full addresses directly in the endpoints:
<service name="XMLService" behaviorConfiguration="MetadataBehavior">
<endpoint address="http://localhost:8888/MyService"
binding="wsHttpBinding"
contract="IXMLService"/>
<endpoint address="http://localhost:8888/MyService/mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
Marc
marc_s
2009-07-07 06:00:09