简体   繁体   English

如何通过 MVC 网站在参考 DLL 中托管 WCF 服务?

[英]How to host a WCF Service in a reference DLL via an MVC Website?

I hope that title is clear enough.我希望这个标题足够清楚。

I have 2 projects, MyProject.Website (ASP.NET MVC3 Front End) and MyProject.WcfService.我有 2 个项目,MyProject.Website(ASP.NET MVC3 前端)和 MyProject.WcfService。 When i host the website, i'd rather not have to host two websites inside of IIS, i'd like to be able to host just MyProject.Website and inside of that reference MyProject.WcfService.当我托管该网站时,我宁愿不必在 IIS 内托管两个网站,我希望能够仅托管 MyProject.Website 和该引用 MyProject.WcfService 内。

I know i can do this via ServiceHost, which should work, but is there a better way?我知道我可以通过 ServiceHost 做到这一点,这应该可以工作,但有更好的方法吗?

Check this post where i demostrated how you can host wcf service dll查看这篇文章,我演示了如何托管 wcf 服务 dll

Create, Host(Self Hosting, IIS hosting) and Consume WCF servcie 创建、托管(自托管、IIS 托管)和使用 WCF 服务

IIS hosting IIS 主机

  1. To host same WCF library in your application create WCF Web application project using WCF web application. To host same WCF library in your application create WCF Web application project using WCF web application.
  2. Delete the files created in the IService.cs and Service.cs file from App_Code folder从 App_Code 文件夹中删除 IService.cs 和 Service.cs 文件中创建的文件
  3. Include WCF library *.dll file which we created.包括我们创建的 WCF 库 *.dll 文件。
  4. Open Service.svc file and modify the single line in it打开 Service.svc 文件并修改其中的单行

    -- <%@ ServiceHost Language="C#" Debug="true" Service="WcfServiceLibrary.Service1" %> -- <%@ ServiceHost Language="C#" Debug="true" Service="WcfServiceLibrary.Service1" %>

  5. Change the web service WEB.Config file to to expose service to client.更改 web 服务 WEB.Config 文件以向客户端公开服务。 ie you need to create Same element as listed above in in the app.config file of service library.即您需要在服务库的 app.config 文件中创建与上面列出的相同的元素。

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

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