开发者

Programmatically connect to a wcf

开发者 https://www.devze.com 2023-02-28 08:05 出处:网络
I need help to figure out how to programmatically开发者_如何学Python connect to a WCF service.

I need help to figure out how to programmatically开发者_如何学Python connect to a WCF service.

This needs to be done without knowing the about the WCF service, I only have an address. I do not have the option to add all the wcf services in the application.

The application I'm working on is going to over watch a number of other applications and verify that they are alive. Perhaps each minute or so.

I have a list of addresses to wcf services that might grow and shrink and thus I need help to build a c# function that can take an address and connect to a wcf service and then request information from that wcf service.

I've searched around a lot and not been able to find information and examples of how this is can be done with c# .net 4.0 and thus I really appreciate your help.

Thanks


What you need to do is create the proxy at runtime and then use the newly created proxy to invoke the service.

This type of dynamic proxy should use the MetadataResolver class to download the metadata from the service and then use the WsdlImporter class to create the contract and binding at runtime.

After the dynamic proxy is compiled you can then invoke the operations on the service by using reflection. There is an implementation and explanation of a WCF dynamic proxy here that might get you started:

http://blogs.msdn.com/b/vipulmodi/archive/2006/11/16/dynamic-programming-with-wcf.aspx

And you can download the code from:

http://code.msdn.microsoft.com/Project/Download/FileDownload.aspx?ProjectName=netfxsamples&DownloadId=3939)


One possibility is to use MetadataExchangeClient to obtain metadata from a live WCF service, or fail with an error, that would serve as a 'ping' solution.


Have you tried to use svcutil tool. You can use it to create different proxy classes (for each service you need one) and then you are able to access services in a very simple way. If a new service (with new metadata) is added to the list you simply extend your app.

For using svcutil you just need to know the service address. Everything else can be done automatically.

0

精彩评论

暂无评论...
验证码 换一张
取 消