How to define endpoints in app.config file?

How to define endpoints with the MEX endpoint in the app.config file and what I need to run my application. I have one service contract called IXMLService and I use WsHttpBinding. Please give an example. After creating app.config, how can I start the service?

+3
source share
2 answers
<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 can write the following console application to host it (by adding the previous app.config file):

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();
        }
    }
}
+6
source

You almost have Darin's answer - you need to specify FULL full addresses for both your service and your mex endpoint, 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>

http://localhost:8888/MyService, MEX http://localhost:8888/mex

, :

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

+2

Source: https://habr.com/ru/post/1711968/


All Articles