简体   繁体   English

不使用.svc文件创建WCF服务

[英]Creating WCF service without .svc file

I am having issues running few files which contains a wcf service. 我在运行包含wcf服务的少量文件时遇到问题。 The service is created without a config file and without a .svc file. 在没有配置文件且没有.svc文件的情况下创建服务。 Is it possible to run a service without a .svc file. 是否可以在没有.svc文件的情况下运行服务。 These are 2 simple C# class files which have their full service requirements, like service contracts and operation contracts. 这些是2个简单的C#类文件,它们具有完整的服务要求,如服务合同和操作合同。

I have tried it calling from another class, but it gives this error:"a project with an output type of class library cannot be started directly" 我试过从另一个类调用它,但它给出了这个错误:“无法直接启动具有类库输出类型的项目”

my question is: is it necessary to have a service.svc file? 我的问题是:是否有必要有一个service.svc文件?

If you don't host your service in IIS, no need for .svc. 如果您不在IIS中托管服务,则不需要.svc。 The reason for .svc in IIS is: IIS中.svc的原因是:

WCF services hosted in IIS are represented as special content files (.svc files) inside the IIS application. IIS中托管的WCF服务在IIS应用程序中表示为特殊内容文件(.svc文件)。 This model is similar to the way ASMX pages are represented inside of an IIS application as .asmx files. 此模型类似于ASMX页面在IIS应用程序中表示为.asmx文件的方式。 A .svc file contains a WCF-specific processing directive (@ServiceHost) that allows the WCF hosting infrastructure to activate hosted services in response to incoming messages. .svc文件包含特定于WCF的处理指令(@ServiceHost),该指令允许WCF托管基础结构激活托管服务以响应传入消息。

.svc file is required when you host the service in IIS. 在IIS中托管服务时需要.svc文件。 The file is actually a text file similar to .asmx file. 该文件实际上是一个类似于.asmx文件的文本文件。 If you open it with any text editor,you would see some details like .asmx file. 如果用任何文本编辑器打开它,你会看到一些像.asmx文件这样的细节。 Such as Language (C#/VB), Service code and Name of the service, Debug etc.. 如语言(C#/ VB),服务代码和服务名称,调试等。

It is not neccessary to have svc file if your not hosting on IIS. 如果您没有在IIS上托管,则不需要svc文件。 Self hosting is example of not having svc file. 自托管是没有svc文件的例子。

Take a look at WCF WebAPI it has lots of cool bits and pieces to allow you to do things like hosting outside of IIS or hosting via a Binding. 看看WCF WebAPI它有很多很酷的部分,可以让你做一些事情,比如在IIS之外托管或通过Binding托管。 this article guides you through some basic services. 本文将指导您完成一些基本服务。 http://www.tugberkugurlu.com/archive/introduction-to-wcf-web-api-new-rest-face-ofnet http://www.tugberkugurlu.com/archive/introduction-to-wcf-web-api-new-rest-face-ofnet

however do note that even when SelfHosting (running a WCF service inside a windows process) you will still need an executable (ie you cant just run a class library by itself) 但请注意,即使SelfHosting(在Windows进程中运行WCF服务),您仍然需要一个可执行文件(即您不能自己运行一个类库)

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

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