How to deploy web service as a single dll? C#

2019-06-14 14:30发布

问题:

I've created a project in VS of type Site. I've created a bunch of asmx services. To make it work on IIS, I just copied cs and asmx files to site's folder. Everything works perfect. Now, when it comes to deploy my services from local pc to development server, I was told to deliver a single dll. I don't see how I can compile a dll on this type of project. Is it possible?

Then, I created an ASP.Net project, put all my stuff there. It created a single dll. But if I put it that folder and tell my asmx, that code behind is in that dll, I get parse error when try to check it in browser.

WebService1.asmx:

<%@ WebService Language="C#" CodeBehind="~/AllWebServices.dll" Class="MyNamespace.WebService1" %>

Maybe I need to add smth in Class attribute?

回答1:

I have Asmx webservices deployed on IIS on remote server.

  • Right-Click on your project in Solution explorer
  • Set Output-type: Class Library
  • Build-ASMX WebService Project
  • Go to the bin folder of your project. You will find dll's there.
  • If you have used any external dlls/libs and want a single dll you have to merge them, using Using Ilmerge to combine multiple dlls in .NET
  • When I deploy my asmx webservice to IIS on remote server. I deploy only

    • bin
    • webservicename.asmx
    • Web.Config

Note: You don't need to change the markup in .asmx file of your webservice. It will automatically find it in the dll in bin folder.