我已经在一个应用程序中创建了一个 Web 服务。现在我需要在我的另一个网站中使用它。我知道如果 Web 服务在同一个应用程序中,例如使用 jquery 提供像“webservicename.asmx/getInventoryForWs”这样的 url,它可以如何完成。我的 jquery 调用代码是
$.ajax({
type: "POST",
url: "http://localhost/DashboardUI/Reports/Marketing/AUSUWs.asmx/getInventoryForWs",
contentType: "application/json; charset="utf-8",
dataType: "jsonp",
success: function (ret) {
alert('success');
},
error: function (httpRequest, textStatus, errorThrown) {
alert("status=" + textStatus + ",error=" + errorThrown);
}
});
这是我的 vb.net 网络服务代码
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Web.Script.Services
' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the
following line.
<System.Web.Script.Services.ScriptService()> _
<WebService(Namespace:="http://microsoft.com/webservices/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class AUSUWs
Inherits System.Web.Services.WebService
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _
Public Function getInventoryForWs() As String
Try
Dim a As New AUSUReport
Dim dt As DataTable = a.getInventoryForWs().Tables(0)
Return (GetJson(dt))
Catch ex As Exception
Throw ex
End Try
End Function
Public Function GetJson(ByVal dt As DataTable) As String
Dim serializer As New System.Web.Script.Serialization.JavaScriptSerializer()
Dim rows As New List(Of Dictionary(Of String, Object))()
Dim row As Dictionary(Of String, Object) = Nothing
For Each dr As DataRow In dt.Rows
row = New Dictionary(Of String, Object)()
For Each col As DataColumn In dt.Columns
row.Add(col.ColumnName.Trim(), dr(col))
Next
rows.Add(row)
Next
Return serializer.Serialize(rows)
End Function
End Class
谁能帮我这个?