简体   繁体   English

从主机调用WCF服务

[英]Calling WCF service from host

I am hosting a WCF service library in an ASP.net web application, which also needs to consume it. 我在ASP.net Web应用程序中托管WCF服务库,它也需要使用它。 What is the best way to do so? 这样做的最佳方法是什么? Should I create a client proxy and invoke the service that way or is there a way of directly calling it? 我应该创建一个客户端代理并以这种方式调用服务,还是有直接调用它的方法? (the library is a project reference after all, and I guess doing so would be faster) (该库毕竟是项目参考,我想这样做会更快)

Since your WCF service library is a project reference for your web application, you could just instantiate the service directly without creating a client proxy. 由于WCF服务库是Web应用程序的项目参考,因此您可以直接实例化服务而无需创建客户端代理。 This approach would indeed be faster since you wouldn't be going through the serialization and deserialization that WCF does. 这种方法的确会更快,因为您无需像WCF那样进行序列化和反序列化。 However, you may wish to create a client proxy and access the service that way. 但是,您可能希望创建一个客户端代理并以这种方式访问​​该服务。 This approach would be useful if there's any chance you may at some point host the service outside of your web application. 如果您有机会在Web应用程序外部托管服务,则此方法将很有用。 If you were to end up moving the service, you would just need to update the endpoint address in your web application's web.config file. 如果最终要移动服务,则只需要更新Web应用程序的web.config文件中的终结点地址即可。

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

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