.NET Framework Developer Center > .NET Development Forums > Windows Communication Foundation > how to use metadata in app.config with multiple endpoints in self hosted service
Ask a questionAsk a question
 

Answerhow to use metadata in app.config with multiple endpoints in self hosted service

  • Tuesday, November 03, 2009 5:53 AMShaveta Mahajan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Hi everybody ,
    Can u tell me please, how to use metadata in app.config with multiple endpoints in self -hosted service,

    when i run the  add the service reference it gave an error:
    Metadata contains a reference that cannot be resolved: 'http://localhost:2508/'.
    please help me out.

Answers

  • Tuesday, November 03, 2009 5:22 PMAmit Sharma RMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    please compare my sample with your scenario..


    using System;
    using System.ServiceModel;
    
    namespace SelfHost
    {
        [ServiceContract]
        interface IContract1
        {
            [OperationContract]
            string Operation1();
        }
    
        public class Service: IContract1
        {
            string IContract1.Operation1()
            {
                return "OP1";
            }
        }
           
        class Program
        {
            static void Main(string[] args)
            {
                Uri httpAddress = new Uri("http://localhost:8002/Service");
                ServiceHost host = new ServiceHost(typeof(Service), httpAddress);
                host.Open();
                Console.WriteLine("host opened");
                Console.Read();
                host.Close();
            }
        }
    }
    
    




    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.serviceModel>
        <services>
          <service name="SelfHost.Service" behaviorConfiguration="beh">
            <endpoint address="svc" binding="basicHttpBinding" contract="SelfHost.IContract1"></endpoint>
            <endpoint address="net.tcp://localhost:8001/Service/net" binding="netTcpBinding" contract="SelfHost.IContract1"></endpoint>
            <endpoint name="mexHttpBinding" contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="beh" >
              <serviceMetadata httpGetEnabled="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>
    
    I am able to add a reference to http://localhost:8002/Service and test the service using WCFTestClient



    Amit Sharma

All Replies

  • Tuesday, November 03, 2009 5:57 AMAmit Sharma RMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    what do you see when you browse to your service metadata using any Browser..   Are you able to see the metadata there?
    My guess is that something is not configured properly in your service and when you browse to the service metadata it should tell you what is wrong. 


    Amit Sharma
  • Tuesday, November 03, 2009 6:11 AMShaveta Mahajan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
      When i rebuild the host service, it rebuild properly but in command prompt It give an error i.e

    "could not find the base address that matches the scheme http for the endpoint with metadata ExchangeHttpBinding."

    My app.config is just like:

    <behavior name="Microsoft.Samples.Silverlight.PollingDuplex.Service.PubSubServiceBehavior">
              <serviceMetadata httpGetEnabled="true"/>
              <serviceDebug includeExceptionDetailInFaults="true"/>
              <serviceThrottling maxConcurrentSessions="2147483647"/>
            </behavior>
            <behavior name="behavior1">
              <serviceThrottling maxConcurrentSessions="2147483647" maxConcurrentCalls="2147483647" maxConcurrentInstances="2147483647"/>
            </behavior>
     <services>
          <service behaviorConfiguration="Microsoft.Samples.Silverlight.PollingDuplex.Service.PubSubServiceBehavior"
            name="JakayaConvo.WCF.JakayaChatService">
            <endpoint address="http://localhost:2508/JakayaChatService" binding="customBinding" bindingConfiguration="Jakayaconfig"
              contract="JakayaConvo.WCF.IJakayaChatService" />
            <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
            <endpoint address="http://localhost:2508/wsservice" binding="wsDualHttpBinding" contract="JakayaConvo.WCF.IJakayaChatService">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>
           
          </service>
  • Tuesday, November 03, 2009 6:36 AMAmit Sharma RMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    when you host your service, are you giving a base address in your ServiceHost ctor?


    Amit Sharma
  • Tuesday, November 03, 2009 7:12 AMShaveta Mahajan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    In Program.cs file, i used

       Uri netTcpAddress = new Uri("net.tcp://localhost:2509/");

                 Uri httpAddress = new Uri("http://localhost:2508");

      ServiceHost serviceHost = new ServiceHost(typeof(JakayaChatService), new Uri[]                           { netTcpAddress,httpAddress });

     serviceHost.Open();

    My App.config is
     <services>
          <service behaviorConfiguration="Microsoft.Samples.Silverlight.PollingDuplex.Service.PubSubServiceBehavior"
            name="JakayaConvo.WCF.JakayaChatService">
            <endpoint address="JakayaChatService" binding="customBinding" bindingConfiguration="Jakayaconfig"
              contract="JakayaConvo.WCF.IJakayaChatService" />
            <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
            
            <!--<endpoint address="wsservice" binding="wsDualHttpBinding" contract="JakayaConvo.WCF.IJakayaChatService">
              <identity>
                <dns value="localhost" />
              </identity>
            </endpoint>-->
            <endpoint
               address="NetTcpService"
               contract="JakayaConvo.WCF.IJakayaChatService"
               binding="netTcpBinding"
              />
          

            <host>
              <baseAddresses>
                <add baseAddress="http://localhost:2508" />
                <add baseAddress="net.tcp://localhost:2509"/>
              </baseAddresses>
              
            </host>
          </service>
          <service behaviorConfiguration="behavior1" name="JakayaConvo.WCF.CrossDomainService">
            <endpoint address="" behaviorConfiguration="HttpEnableBehavior"
              binding="webHttpBinding" contract="JakayaConvo.WCF.ICrossDomain" />
          </service>
        </services>
  • Tuesday, November 03, 2009 5:22 PMAmit Sharma RMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     AnswerHas Code
    please compare my sample with your scenario..


    using System;
    using System.ServiceModel;
    
    namespace SelfHost
    {
        [ServiceContract]
        interface IContract1
        {
            [OperationContract]
            string Operation1();
        }
    
        public class Service: IContract1
        {
            string IContract1.Operation1()
            {
                return "OP1";
            }
        }
           
        class Program
        {
            static void Main(string[] args)
            {
                Uri httpAddress = new Uri("http://localhost:8002/Service");
                ServiceHost host = new ServiceHost(typeof(Service), httpAddress);
                host.Open();
                Console.WriteLine("host opened");
                Console.Read();
                host.Close();
            }
        }
    }
    
    




    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <system.serviceModel>
        <services>
          <service name="SelfHost.Service" behaviorConfiguration="beh">
            <endpoint address="svc" binding="basicHttpBinding" contract="SelfHost.IContract1"></endpoint>
            <endpoint address="net.tcp://localhost:8001/Service/net" binding="netTcpBinding" contract="SelfHost.IContract1"></endpoint>
            <endpoint name="mexHttpBinding" contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
          </service>
        </services>
        <behaviors>
          <serviceBehaviors>
            <behavior name="beh" >
              <serviceMetadata httpGetEnabled="true" />
            </behavior>
          </serviceBehaviors>
        </behaviors>
      </system.serviceModel>
    </configuration>
    
    I am able to add a reference to http://localhost:8002/Service and test the service using WCFTestClient



    Amit Sharma
  • Wednesday, November 04, 2009 4:57 AMShaveta Mahajan Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    do you have sample to consume this above coding in asp.net 
  • Friday, November 06, 2009 8:03 AMRiquel_DongModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    In ASP.NET application, you can add service Refererence(or Add Web services) to generate the proxy class and configuration information for invoking WCF service in this situation.

    Best regards,
    Riquel
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.