質問

I need to use a ServiceReference object in an plugin I’m writing. However, this plugin has its own app.config file separate from the parent program’s config file. I know how to access this secondary config file, but I still don’t know how to use that data in the constructor for my ServiceReference object. The constructors for the object ask for string variables such as endpointConfigurationName or remoteAddress, but then my program can’t find the matching endpointConfigurationName in my secondary config file. How do I force the program to use my secondary “myConfiguration” Configuration object?

ServiceModelSectionGroup serviceModel = ServiceModelSectionGroup.GetSectionGroup(myConfiguration);
myClient = new MyClient();
役に立ちましたか?

解決

I used @paulsm4 suggestion and found this page on Microsoft's site. Using that, I ended-up with this, and it's working great:

ChannelFactory<IMyService> myFactory = new ChannelFactory<IMyService>(new WebHttpBinding(), myRemoteAddress);
myFactory.Endpoint.Behaviors.Add(new WebHttpBehavior());
myClient = cf.CreateChannel();

I realize this doesn't exactly solve the original question, but I don't think there's a way to read ALL of the binding info from an alternate config file. If there is, I welcome someone to answer the original question.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top