[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 787
  • Last Modified:

Call simple web service via Soap Client

I am new Soap in VB 6.  I thought I'd be able to just figure it out as I normally do.  However this proved to be a slow process because I cannot find a help file that contains description of the SoapClient object methods, properties etc.  I am looking a code sample that calls a service passes a name (string) then returns "hello" & name - that simple.  I am also looking for the location of the Soap toolkit help file (I have soap toolkit installed) This is actually more important than the sample

Many thanks
0
gbzhhu
Asked:
gbzhhu
  • 3
1 Solution
 
gbzhhuAuthor Commented:
Both didn't help

First one
I am already to create the soapclient object and successfully call MSSoapInit method.  I didn't know where to go from there.  How to call the SayHi method of my service and pass a string to it displaying the returned string.  The service is written in Java (J2EE).  When I tried soapclient.SayHi("MyName") I get an error saying

No Deserializer found to deserialize a ':name' using encoding style 'http://schemas.xmlsoap.org/soap/encoding/'.

The second one is for Office VBA.  I need this from VB 6.  I only have Office 97 anyway which doesn't support all that stuff

 
0
 
gbzhhuAuthor Commented:
Ok, go it fixed

This is the page that helped me

http://www.soapuser.com/client4.html

And this is my code as it stands, so I hope it helps someone else someday.  Live long EE

Option Explicit

Private Const ENC = "http://schemas.xmlsoap.org/soap/encoding/"
Private Const XSI = "http://www.w3.org/1999/XMLSchema-instance"
Private Const XSD = "http://www.w3.org/1999/XMLSchema"
Private Const URL = "http://ourserver:9888/WS_Hello01/servlet/rpcrouter"
Private Const URI = "uri:HiWebService"
'Private Const URI = "http://companyname.com.wsdl/HiWebServiceService"
Private Const Method = "sayHello"

Private Sub Command1_Click()
    'Instantiate your SOAP Connector, Serializer and Reader. The Connector will handle the HTTP Connection, the Serializer will help you build the SOAP Envelope and the Reader will help you to access the result.
    Dim Connector As SoapConnector30
    Dim Serializer As SoapSerializer30
    Dim Reader As SoapReader30
   
    Set Connector = New HttpConnector30
    Set Serializer = New SoapSerializer30
    Set Reader = New SoapReader30
   
    'Prepare the Connector to talk to the SOAP Server. Note that the "SoapAction" data is not consequential on the server side so the contents can be anything at all - It is a good idea to set it to the URI and Method name for easier identification when you are debugging and reading the SOAP messages.
    Connector.Property("EndPointURL") = URL
    Call Connector.Connect
    Connector.Property("SoapAction") = URI & "#" & Method
    Call Connector.BeginMessage
   
    'Associate your Serializer with your Connector.
    Serializer.Init Connector.InputStream
   
    'Start the SOAP Envelope and specify the Encoding and XML-Schema.
    Serializer.StartEnvelope , ENC
    Serializer.SoapNamespace "xsi", XSI
    Serializer.SoapNamespace "SOAP-ENC", ENC
    Serializer.SoapNamespace "xsd", XSD
   
    'Start the body of the message - the root element is always the Service URI and method.
    Serializer.StartBody
    Serializer.StartElement Method, URI, , "method"
   
    'Write each method parameter out as a child to the root element.
    Serializer.StartElement "name"
    Serializer.SoapAttribute "type", , "xsd:string", "xsi"
    Serializer.WriteString "Hassan"
    Serializer.EndElement
   
    'End the root element, the body and the envelope.
    Serializer.EndElement
    Serializer.EndBody
    Serializer.EndEnvelope
   
    'Ending the message causes it to be sent.
    Connector.EndMessage
   
    'Load the result into the Reader.
    Reader.Load Connector.OutputStream
   
    'If no fault loading the Reader then you can go ahead and pull the result of the invocation out of the DOM (Document Object Model) contained in the reader. There are many ways to do this ranging from methods highly specialised to the task at hand (and thus quite efficient) to more general and reusable methods that are not so efficient (like the method you will see in the downloadable source).
    If Not Reader.Fault Is Nothing Then
      MsgBox Reader.FaultString.Text, vbExclamation
    Else
MsgBox Reader.Dom.Text
    End If

End Sub



0
 
gbzhhuAuthor Commented:
Aryaomni,  I'll accept your answer as you are the one who tried to help.  Thanks
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now