.NET Web服务“无法创建类型”

时间:2010-07-05 23:52:18

标签: .net web-services

我的.NET Web服务的标记和代码隐藏文件内容如下(几乎与VS生成的内容):

Services.asmx:

<%@ WebService Language="VB" CodeBehind="Services.asmx.vb" Class="Services" %>

Services.asmx.vb:

Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.ComponentModel

<System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<ToolboxItem(False)> _
Public Class Services
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function HelloWorld() As String
        Return "Hello World"
    End Function
End Class

当我尝试访问网络服务时,我得到:

分析程序错误消息:无法创建“服务”类型

我尝试使用命名空间在标记中限定Services类规范,但无济于事。

当我将代码隐藏在与.asmx相同的文件中时,一切正常。

4 个答案:

答案 0 :(得分:3)

因此,当我将构建配置更改为Any CPU时,它的工作原理是因为包含该类型的.dll最终位于bin文件夹中。当构建配置设置为x86时,.dll仅在bin / x86 / Debug或bin / x86 / Release中结束,其中IIS不显示。看起来很傻。我错过了什么吗?

答案 1 :(得分:2)

我想说这是与命名空间匹配的类名相关的问题。您是否尝试将Services类重命名为其他类?

答案 2 :(得分:1)

实际上,我有两个文件夹(x86和x64)用于两种配置,而IIS只在主bin文件夹中查找dll。我复制了dll文件,它立即起作用。

答案 3 :(得分:0)

我遇到了这个问题正在编译网络项目。名称全部匹配,在另一个解决方案中正常工作。

注意到这是一个'网络'项目。删除了项目并将其作为现有项目添加回来,并且在没有被识别为“web”项目的情况下返回 - 然后编译并运行正常。