没有 App_Code 的 ASP.Net WCF 服务 [英] ASP.Net WCF Service with no App_Code

查看:31
本文介绍了没有 App_Code 的 ASP.Net WCF 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个 WCF 服务以在我的 ASP.Net 网站(不是项目)上使用,该服务要么没有代码隐藏文件,这是传统 asmx 样式服务的一个选项,但没有出现 用于 wcf 服务,或者将其代码存储在单独的代码项目中并仅由 svc 文件公开.

I want to create a WCF Service for use on my ASP.Net website (not project) that either has no codebehind file, which was is an option for a traditional asmx style service but doesn't appear to be for wcf services, or which stores it's code in a separate code project and is just exposed by the svc file.

我尝试将代码文件从 app_code 移动到我的单独项目中,但无法弄清楚如何链接它们,因为从 svc 文件中删除代码隐藏属性会立即引发错误.

I tried just moving the code file from app_code into my separate project but couldn't figure out how to link them, as removing the codebehind attribute from the svc file immediately throws an error.

推荐答案

您可以让 Web 项目中的 SVC 文件指向包含在单独 DLL 中的类.您不必在 App_Code 目录中放置 SVC代码隐藏".这很容易做到.您的 SVC 文件只需要有一个属性 - Service.这是我在工作场所使用的示例:

You can have your SVC file in your web project point to a class that's contained in a separate DLL. You don't have to have your SVC "code behind" in your App_Code directory. It's very easy to do. Your SVC file just needs to have a single attribute - Service. Here's a sample of one that I use where I work:

<%@ ServiceHost Service="My.Qualified.Service.Class.Name" %>

我在 App_Code 文件夹中没有任何代码.此 SVC 的所有逻辑都包含在一个单独的 DLL(恰好是 My.Qualified.Service.Class.dll)中.我的服务名称是实现类的名称;这是唯一的警告.

I do not have any code behind in the App_Code folder. All of the logic for this SVC is contained in a separate DLL (which happens to be My.Qualified.Service.Class.dll). My service name is the name of the implementing class; that's the only caveat.

我的 web.config(在 system.serviceModel 内)像这样引用这个服务:

My web.config (inside system.serviceModel) references this service like so:

<service name="My.Qualified.Service.Class.Name">
    <endpoint address=""
     binding="webHttpBinding"
     contract="My.Qualified.Service.Class.IName" />
</service>

之后我的服务逻辑是直接的 WCF 代码.我的 IName 接口定义了我的操作;Name 实现它们.

My service's logic is straight-forward WCF code after that. My IName interface defines my operations; Name implements them.

我希望这会有所帮助!

这篇关于没有 App_Code 的 ASP.Net WCF 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆