tags:

views:

365

answers:

3

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 ?

A: 

Please have a look at this link

I think it answers your question.

Prashanth
+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"/&gt;
                </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
This probably won't work - the MEX endpoint doesn't have a full, complete address, and there's no "baseAddresses" defined......
marc_s
@marc_s, you're correct, I've assumed IIS. I modified my post accordingly.
Darin Dimitrov
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
thank you very much Darin , everything is working perfectaly..
Praveen
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/"/&gt;
            </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