Pregunta

Scenario: I am consuming a web service in my class library project and it generates a binding name and end point in app.config. If I reference the class library in my UI project, I also have to include the same configuration in web.config. My problem is I don't want to include this configuration in web.config because of the dependency. I want to use assembly as it own with out any dependency.

My solution approach: When I create the instance of proxy class in the class library project it shows me constructor to pass binding and endpoint. Example

wsProxy proxyClass = new wsProxy(System.ServiceModel.Channels.Binding binding, System.ServiceModel.Endpoint endpoint)

I was wondering if I can pass the same binding and endpoint that I have in app.config so that I don't have to include either in app.config and web.config.

¿Fue útil?

Solución

Yes, you can create these classes without having matching configuration in the main .config file. Where you get that configuration is up to you; it could be App.config, a YML configuration file, a database, etc. As long as your code satisfies the constructor requirements for the classes you're instantiating, you'll be fine.

Otros consejos

With WCF, everything defined in your configuration file can be done programmatically.

You just need to create the objects needed to instantiate your client. Depending on the WCF features you want your application to be leveraging, you'll need classes like EndpointAddress, AddressHeaderCollection, Uri, EndpointIdentity (DnsEndpointIdentity or SpnEndpointIdentity), Binding (WSHttpBinding, NetTcpBinding etc.). And you might want to have these objects populated from a decoupled, centralized configuration store such as a database.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top