简体   繁体   English

结合WCF服务库和WCF服务应用程序

[英]Combining WCF Service Library and WCF Service Application

Thanks to Stack Overflow and a few other sites, I understand the difference between the WCF LIbrary and WCF Service Application templates. 感谢Stack Overflow和其他一些站点,我理解WCF LIbrary和WCF服务应用程序模板之间的区别。

Briefly the Library is a DLL that allows for multiple types of hosting. 简而言之,Library是一个允许多种类型托管的DLL。 It does not have a .svc file. 它没有.svc文件。 While the Service Applications template is created specifically with IIS in mine with a .svc file. 虽然服务应用程序模板是使用.svc文件专门使用IIS创建的。

I read that WCF Service Library is the best way because it is the most flexible. 我读到WCF服务库是最好的方法,因为它是最灵活的。 But I NEVER see instructions on how to do it apart from using the WCF Service Application template. 但除了使用WCF服务应用程序模板之外,我从未看到有关如何执行此操作的说明。

Is it difficult to go from WCF Service Library to hosting on IIS from scratch? 是否很难从WCF服务库转到IIS从头开始托管? I have two books on WCF and I've read numerous articles and none of them cover how to create a svc file using only the WCF Service Library and No WCF Service Application. 我有两本关于WCF的书,我读了很多文章,但没有一篇介绍如何仅使用WCF服务库和无WCF服务应用程序创建一个svc文件。 Why? 为什么?

Nigel Shaw also mentions on the following link that there are limitations to using the Library option. Nigel Shaw还在以下链接中提到使用“库”选项存在限制。 What is the purpose of WCF Service Library? WCF服务库的目的是什么?

Basically What I want to do is host the WCF Service on both IIS and a Windows Service. 基本上我想要做的是在IIS和Windows服务上托管WCF服务。 Thus it appears that the combined way is the best way. 因此,似乎组合方式是最好的方式。 Nevertheless, I'm trying to learn why there aren't more instructions on using the WCF Service Library. 不过,我试图了解为什么没有更多关于使用WCF服务库的说明。

Ok, I did find a couple of articles that seem to use an ASP.NET Web Application and tells you how to create a text file for the svc file. 好的,我确实找到了一些似乎使用ASP.NET Web应用程序的文章,并告诉您如何为svc文件创建文本文件。

This article: http://debugmode.net/2010/12/25/wcf-service-library-creating-hosting-and-consuming-wcf-service-with-wcf-service-library-project-template/ 本文: http//debugmode.net/2010/12/25/wcf-service-library-creating-hosting-and-consuming-wcf-service-with-wcf-service-library-project-template/

and this one: http://danielvanwyk.wordpress.com/2010/04/30/create-host-and-consume-a-wcf-service-using-the-wcf-service-library-template-in-visual-studio-2008/ 这一个: http//danielvanwyk.wordpress.com/2010/04/30/create-host-and-consume-a-wcf-service-using-the-wcf-service-library-template-in-visual-工作室2008 /

But what I still don't understand is why is the ASP.NET Application still needed? 但我仍然不明白为什么仍然需要ASP.NET应用程序? And If i add a svc file does it get placed in the wwwroot directory (that seems to be where the WCF Service Application places it .svc file? 如果我添加一个svc文件,它是否放在wwwroot目录中(这似乎是WCF服务应用程序放置.svc文件的位置?

Thanks! 谢谢!

A WCF Service Library has to be hosted in order to be used - you can host it in IIS, a Windows Service or some self-hosted option (like a console app, WinForm, WPF, etc). 必须托管WCF服务库才能使用 - 您可以在IIS,Windows服务或某些自托管选项(如控制台应用程序,WinForm,WPF等)中托管它。

In the last two links you provide, they're demonstrating how to host the library in an ASP.NET service application, but you don't have to use that project template to host it. 在你提供的最后两个环节,他们演示如何举办库在ASP.NET服务应用程序,但你不必使用项目模板来承载它。 It's simply one option out of several. 它只是其中一种选择。

You can create an IIS-hosted implementation of your class library without using a VS project template, but you'll need to manually add the .svc file and the Web.config. 您可以在不使用VS项目模板的情况下创建类库的IIS托管实现,但是您需要手动添加.svc文件和Web.config。 I have done this several times: 我这样做了好几次:

  1. Create a folder (I normally put mine in the wwwroot folder of inetpub , but you can put it wherever you desire). 创建一个文件夹(我通常把它放在inetpubwwwroot文件夹中,但你可以把它放在任何你想要的地方)。
  2. Create a bin folder in the folder you created in step 1, and put the WCF service library and any other required assemblies in it. 在步骤1中创建的文件夹中创建bin文件夹,并将WCF服务库和任何其他必需的程序集放入其中。
  3. Add a .svc file with the appropriate markup in the folder created in step 1. 在步骤1中创建的文件夹中添加带有相应标记的.svc文件。
  4. Add a Web.config with the appropriate service model configuration in the folder created in step 1. 在步骤1中创建的文件夹中添加具有相应服务模型配置的Web.config。
  5. Create an application in IIS that points to the folder you created. 在IIS中创建指向您创建的文件夹的应用程序。

Now you have an IIS-hosted instance of your service. 现在您有一个IIS托管的服务实例。 You can then use another copy of the WCF service library for your Windows-Service hosted instance. 然后,您可以为Windows服务托管实例使用WCF服务库的另一个副本。

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

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