Use new ChannelFactory<TChannel>(string) if the config is in a string?
I would like to use the ChannelFactory to create a WCF Client for a given endpoint.
The problem is that I don't have a web.config or app.config, but I do have the whole <system.serviceModel>
XML block in a string.
I do not want to manually parse that out and programatically create the BIndings and Endpoints when I already have the configuration.
Is there a way to tell the ChannelFactory to just use that block as it's configuration? Or at lea开发者_如何学编程st create a ServiceEndpoint?
There's a technique described in this blog entry.
It isn't as simple as one line of code, but at least it's working at a level higher than raw XML.
You can manually create binding and endpoint address to create an instance of the CHannelFactory, something like:
BasicHttpBinding binding = new BasicHttpBinding() {
Name = "Bindingname"
// Goes all the necessary members to set.
};
EndpointAddress endpoint = new EndpointAddress("http://serviceendpoint.com");
ChannelFactory<IContract> factory = new ChannelFactory<IContract>(binding, endpoint);
Then you can try using factory.CreateChannel() to explore the members of it before your ServiceEnpoint, Behaviors, etc.
Hope this help, thanks.
Found a better solution: ConfigurationChannelFactory<TChannel>
allows creating a WCF Channel from a custom configuration.
精彩评论