[英]How to make dynamically generated .net service client read configuration from another location than *.config files
I've currently written code to use the ServiceContractGenerator to generate web service client code based on a wsdl, and then compile it into an assembly in memory using the code dom. 我目前编写的代码是使用ServiceContractGenerator生成基于wsdl的Web服务客户端代码,然后使用代码dom将其编译到内存中的程序集中。 I'm then using reflection to set up the binding, endpoint, service values/types, and then ultimately invoke the web service method based on xml configuration that can be altered at run time.
然后我使用反射来设置绑定,端点,服务值/类型,然后最终调用基于可在运行时更改的xml配置的Web服务方法。
This all currently works fine. 这一切目前工作正常。 However, the problem I'm currently running into, is that I'm hitting several exotic web services that require lots of custom binding/security settings.
但是,我目前遇到的问题是,我遇到了几个需要大量自定义绑定/安全设置的异国情调的Web服务。 This is forcing me to add more and more configuration into my custom xml configurations, as well as the corresponding updates to my code to interpret and set those binding/security settings in code.
这迫使我在我的自定义xml配置中添加越来越多的配置,以及我的代码的相应更新,以解释和设置代码中的绑定/安全设置。
Ultimately, this makes adding these 'exotic' services slower, and I can see myself eventually reimplementing the 'system.serviceModel' section of the web or app.config file, which is never a good thing. 最终,这使得添加这些“异国情调”的服务变得更慢,我可以看到自己最终重新实现了web或app.config文件的'system.serviceModel'部分,这从来都不是一件好事。
My question is, and this is where my lack of experience .net and C# shows, is there a way to define the configuration normally found in the web.config or app.config 'system.serviceModel' section somewhere else, and at run time supply this to configuration to the web service client? 我的问题是,这是我缺乏经验.net和C#显示的地方,有没有办法定义通常在web.config或app.config'system.serviceModel'部分中找到的配置,在运行时将此配置提供给Web服务客户端?
Is there a way to attach an app.config directly to an assembly as a resource or any other way to supply this configuration to the client? 有没有办法将app.config作为资源直接附加到程序集或以其他任何方式将此配置提供给客户端?
Basically, I'd like attach an app.config only containing a 'system.serviceModel' to the assembly containing a web service client so that it can use its configuration. 基本上,我想将一个仅包含'system.serviceModel'的app.config附加到包含Web服务客户端的程序集,以便它可以使用其配置。 This way I wouldn't need to handle every configuration under the sun, I could let .net do it for me.
这样我就不需要处理太阳下的每一个配置,我可以让.net为我做。
Fyi, it's not an option for me to put the configuration for every service in the app.config for the running application. Fyi,我不能选择为app.config中的每个服务配置正在运行的应用程序。
Any help would be greatly appreciated. 任何帮助将不胜感激。
Thanks in advance! 提前致谢! Bryan
布赖恩
Are your proxy classes deriving from ClientBase<T>
? 你的代理类派生自
ClientBase<T>
吗? If so, then there is a constructor that accepts a Binding
and an EndpointAddress
. 如果是这样,那么有一个接受
Binding
和EndpointAddress
的构造函数。 You should be able to use those instead of the corresponding configuration data. 您应该能够使用它们而不是相应的配置数据。
The following couple links talk about loading WCF Configuration settings from config files other than the app.config. 以下几个链接讨论从app.config以外的配置文件加载WCF配置设置。 May be what you are looking for but not certain.
可能是你在寻找但不确定。
http://blogs.msdn.com/dotnetinterop/archive/2008/09/22/custom-service-config-file-for-a-wcf-service-hosted-in-iis.aspx http://blogs.msdn.com/dotnetinterop/archive/2008/09/22/custom-service-config-file-for-a-wcf-service-hosted-in-iis.aspx
http://weblogs.asp.net/cibrax/archive/2007/10/19/loading-the-wcf-configuration-from-different-files-on-the-client-side.aspx http://weblogs.asp.net/cibrax/archive/2007/10/19/loading-the-wcf-configuration-from-different-files-on-the-client-side.aspx
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.