简体   繁体   中英

Consume ASMX Webservice From Classic ASP Using SOAP Client 3.0

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM