简体   繁体   English

WCF并将代理代码移动到DLL。可能吗?

[英]WCF and moving the proxy code to a DLL. Is it possible?

it looks like I am not able to succesfully move my WCF proxy code into a separate DLL (as opposed to an EXE as I can see in all the examples I have run into). 看起来我无法成功地将我的WCF代理代码移动到一个单独的DLL中(与我在所有遇到的示例中都能看到的EXE相反)。

The reason I am trying to do this is that I would like my proxy code to be invoked by different clients (possibly unmanaged code), which might not know anything about WCF but just need to access to the services (through a Facade exposed by the proxy maybe?). 我试图这样做的原因是我希望我的代理代码由不同的客户端(可能是非托管代码)调用,这可能对WCF一无所知,但只需要访问服务(通过由代理可能?)。

Whenever I move the following code that creates a new proxy to a different VS project within the same solution, I get the dreaded " Could not find default endpoint element that references contract 'localhost.IRemoteCommandService' in the ServiceModel client configuration section" exception . 每当我移动下面的代码,在同一个解决方案中为另一个VS项目创建一个新代理时,我就会遇到可怕的“ 无法在ServiceModel客户端配置部分中找到引用契约'localhost.IRemoteCommandService'的默认端点元素”异常

localhost.RemoteCommandServiceClient proxy = 
    new localhost.RemoteCommandServiceClient();

The same code works smoothly whenever used within a Main method in the same project where the proxy code is (auto-generated from Visual Studio). 只要在代理代码所在的同一项目中的Main方法中使用(从Visual Studio自动生成),相同的代码就可以顺利运行。

Any idea? 任何的想法? I hope that the client code of my proxy does not need to have the service model XML configuration as the proxy, because that would defeat the purpose I am moving the WCF proxy code into a DLL in the first place. 我希望我的代理的客户端代码不需要将服务模型XML配置作为代理,因为这将破坏我首先将WCF代理代码移动到DLL中的目的。

Thanks, Stefano 谢谢,斯特凡诺

The endpoints are indeed normally specified in the configuration file. 通常在配置文件中指定端点。 You must look at the serviceModel data in the config file, and copy it into your calling app.config - or you need to use the more verbose way of creating the proxies in your code (ie specifying the address, binding, configuration etc through code to the constructors). 您必须查看配置文件中的serviceModel数据,并将其复制到您的调用app.config中 - 或者您需要使用在代码中创建代理的更详细的方法(即通过代码指定地址,绑定,配置等)到建设者)。

If you don't want to have to endpoint configuration on the client, you'll have to embed it into your proxy dll by specifying everything in code. 如果您不想在客户端上进行端点配置,则必须通过在代码中指定所有内容将其嵌入到代理dll中。

Another option would be to use a dynamic proxy, like this one , which would allow you to not have the serviceModel in your client apps. 另一种选择是使用动态代理,像这样的一个 ,这样可以让你不必在你的客户端应用程序的serviceModel。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM