简体   繁体   中英

How to Get WCF endpoint address url in C#

Is there a way I can read end point address based on service client name?

Here is My ServiceReference Name:

TestServiceReference.TestServiceClient TestClient = new TestServiceReference.TestServiceClient ();

Here is my web.config file

 <endpoint address="http://....................../TestService.svc"
 behaviorConfiguration="webEndpoint" binding="webHttpBinding"
 bindingConfiguration="webHTTPBinding_abc" contract="TestServiceReference.ITestService" />**

Like Below URL

var url = " http://............./TestService.svc ";

Give a try with :

TestClient.InnerChannel.RemoteAddress

Regards

TestClient.InnerChannel.RemoteAddress

Okay it was pretty easy to do, I just needed to use the MetadataExchangeClient to get the config. In the code all I had to do to get the MetaData Xml was this:

var meta = new System.ServiceModel.Description.MetadataExchangeClient(new Uri("net.tcp://10.0.2.124:9000/TeraService/SetInstruments/mex"), System.ServiceModel.Description.MetadataExchangeClientMode.MetadataExchange);
var data = meta.GetMetadata();
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(data.GetType());
TextWriter writer = new StreamWriter("xmlfile.xml");
x.Serialize(writer, data);
writer.Close();

Now I just need to spend some time getting the endpoints from that config.

TestClient.Endpoint.Address.Uri对我有用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM