ASP.Net WCF Service with no App_Code
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.
I tried just moving the code file from app_code into my separate project but couldn't figure out how to link the开发者_JS百科m, as removing the codebehind attribute from the svc file immediately throws an error.
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" %>
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.
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>
My service's logic is straight-forward WCF code after that. My IName
interface defines my operations; Name
implements them.
I hope this helps!
Here is a video that demonstrates how to implement WCF in a way that (I think) allows you to do what you are asking about. You can separate your contracts, services, etc so that you can easily reuse your service. You would need to be able to add references so maybe converting the site to a web app may be the best thing. This would allow to keep your service in a separate project and simply expose it in your web app after referencing your service projects dll.
http://www.dnrtv.com/default.aspx?showNum=122
精彩评论