开发者

Consume ASMX Webservice From Classic ASP Using SOAP Client 3.0

开发者 https://www.devze.com 2023-01-17 13:20 出处:网络
I made a webservice in VB.Net with a method returning a custom class or object. <WebMethod()> _ Public Function CreatePerson(ByVal LastName As String, ByVal FirstName As String) As Person

I made a webservice in VB.Net with a method returning a custom class or object.

<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 S开发者_运维技巧tring
    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

I can consume it from another ASP.NET Application but the problem is when i try to consume it from Classic ASP through SOAP Client 3.0

<% 

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) 

%>

I get an error:

Microsoft VBScript runtime error '800a01a8'

Object required

at "Response.Write(Result.LastName)" Line.

I can see Result is a string array with no elements


I believe that the root cause of the error is the lack of a Set keyword on the line that invokes the web service method. It should look like:

Set Result = oSoapClient.CreatePerson("Sassaroli", "Rinaldo")

That will get you past your initial problem. After that you'll need to read the result object. Your subsequent line of code:

Response.Write(Result.LastName)

will most likely result in another error. That's because the result you're getting is not really a "Person" object, it's an XML representation of that object. You can verify this with the following code:

<% 
    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 )
%>

The type that will be shown by the TypeName call will be IXMLDomSelection. You can access nodes for this object through methods and properties that are documented here.

The last line of code will display the value of the LastName property.

Hope this leads you in the correct direction.

0

精彩评论

暂无评论...
验证码 换一张
取 消