众所周知,如果我们使用visual studio构建Web服务,visual studio会自动生成两个文件,第一个是.asmx,第二个是.vb作为代码。
在代码背后(.vb)我得到的是这样的:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld() As String
Return "Hello World"
End Function
End Class
在.asmx文件中,我得到的是这样的:
<%@ WebService Language="VB" CodeBehind="~/App_Code/WebService.vb" Class="WebService" %>
问题是
答案 0 :(得分:0)
是的,这是可能的。
请参阅以下链接:
Why do asmx web services have a markup file?
<%@ WebService Language="C#" Class="WebService1" %>
using System.Web;
using System.Web.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
public class WebService1 : WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}
答案 1 :(得分:0)
请参阅示例vb编码
<%@ WebService Language="VB" Class="WebService" %>
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld1() As String
Return "Hello World"
End Function
End Class
与其他Web方法调用一样,它也列在Web方法列表中。
左键单击您的项目添加服务参考 - &gt;发现---&gt;展开+符号
应该在那里列出Web方法。
答案 2 :(得分:0)
您需要手动创建网络重新引用(添加服务引用)
webservice .asmx文件示例
<%@ WebService Language="VB" Class="WebService" %>
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService
Inherits System.Web.Services.WebService
<WebMethod()> _
Public Function HelloWorld1() As String
Return "Hello World"
End Function
End Class
更改我们的配置设置如下:
web.config代码
<security mode="none">
<transport clientCredentialType="None" proxyCredentialType="None"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm"/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
sample.aspx页码
<%@ Import Namespace="System.ServiceModel" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<% Dim obj As New WebServiceSoapClient
Response.Write(obj.HelloWorld1())%>
</div>
</form>
</body>
</html>