我使用返回自定义类或对象的方法在VB.Net中创建了一个Web服务。
<WebMethod()> _
Public Function CreatePerson(ByVal LastName As String, ByVal FirstName As String) As Person
Return New Person(LastName, FirstName)
End Function
Public Class Person
Public Sub New()
End Sub
Public Sub New(ByVal LastName As String, ByVal FirstName As String)
_LastName = LastName
_FirstName = FirstName
End Sub
Private _LastName As String
Public Property LastName() As String
Get
Return _LastName
End Get
Set(ByVal value As String)
_LastName = value
End Set
End Property
Private _FirstName As String
Public Property FirstName() As String
Get
Return _FirstName
End Get
Set(ByVal value As String)
_FirstName= value
End Set
End Property
End Class
我可以从其他ASP.NET应用程序中使用它,但问题是当我尝试通过SOAP Client 3.0从Classic ASP使用它时
<%
Dim Result, oSoapClient
Set oSoapClient = Server.CreateObject("MSSOAP.SoapClient30")
oSoapClient.ClientProperty("ServerHTTPRequest") = True
Call oSoapClient.mssoapinit ("http://MyServer/MyWebService/MyWebService.asmx?WSDL")
Result = oSoapClient.CreatePerson("Sassaroli", "Rinaldo")
Response.Write(Result.LastName)
%>
我收到错误:
Microsoft VBScript运行时错误'800a01a8'
需要对象
at“Response.Write(Result.LastName)”Line。
我可以看到Result是一个没有元素的字符串数组
答案 0 :(得分:1)
我认为错误的根本原因是在调用Web服务方法的行上缺少Set
关键字。它应该看起来像:
Set Result = oSoapClient.CreatePerson("Sassaroli", "Rinaldo")
这会让你超越你最初的问题。之后,您将需要读取结果对象。您的后续代码行:
Response.Write(Result.LastName)
很可能会导致另一个错误。那是因为你得到的结果实际上不是“人”对象,它是该对象的XML表示。您可以使用以下代码进行验证:
<%
Dim Result, oSoapClient
Set oSoapClient = Server.CreateObject("MSSOAP.SoapClient30")
oSoapClient.ClientProperty("ServerHTTPRequest") = True
Call oSoapClient.mssoapinit ("http://MyServer/MyWebService/MyWebService.asmx?WSDL")
Set Result = oSoapClient.CreatePerson("Sassaroli", "Rinaldo")
Response.Write( TypeName( Result ) & "<br/>" & vbCrLf )
Response.Write( Result.item(0).text )
%>
TypeName调用将显示的类型将是IXMLDomSelection。您可以通过记录的here。
方法和属性访问此对象的节点最后一行代码将显示LastName属性的值。
希望这能引导你走向正确的方向。