问题
I have a free hosting service that is stuck in ASP.NET 2.0. Additionally, it constrains users to only inline versions (no codebehind). However, it does allow references to custom components. I have built an inline .asmx and would, ideally, like to 'include'/'use' a component I've built. How do I do this inline? I've tried 'using [Namespace]', but get a compilation error. I've also tried using, in the WebMethod [Namespace of Component].[Method] as well. Again, this produces a compilation error. I can't seem to find any documentation on how to do this else where. The component is not compiled into a DLL and will work if referenced in a web form.
回答1:
Use the Import
directive to import a namespace:
<%@ Import namespace="My.Namespace" %>
EDIT: Sorry for the misinformation. You'll want to use the Assembly
directive for an ASMX web service:
<%@ Assembly Name="MyAssembly" %>
or
<%@ Assembly Src="path/myFile.cs" %>
Since the code you are referencing is not compiled, you'll want to use the latter version of the directive to point to the source file. The Src
attribute points to a source file to dynamically compile and link against.
来源:https://stackoverflow.com/questions/8345875/how-do-i-reference-a-component-in-an-inline-web-service