.NET Framework Developer Center >
.NET Development Forums
>
Windows Communication Foundation
>
how to use metadata in app.config with multiple endpoints in self hosted service
how to use metadata in app.config with multiple endpoints in self hosted service
- 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
- 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(); } } }
I am able to add a reference to http://localhost:8002/Service and test the service using WCFTestClient<?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>
Amit Sharma- Marked As Answer byRiquel_DongModeratorMonday, November 09, 2009 1:36 AM
All Replies
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- 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>
when you host your service, are you giving a base address in your ServiceHost ctor?
Amit Sharma- In Program.cs file, i usedUri 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>--><endpointaddress="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>
- 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(); } } }
I am able to add a reference to http://localhost:8002/Service and test the service using WCFTestClient<?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>
Amit Sharma- Marked As Answer byRiquel_DongModeratorMonday, November 09, 2009 1:36 AM
- do you have sample to consume this above coding in asp.net
- 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.


