Creativity and Innovation

Just another weblog

Leave a comment

Invoking JAVA SOAP webservice from VBA

  1. Requirement
    1. Tomcat Apache Server 7.0
    2. JDK 1.6
    3. Apache CXF 2.0 Webservice jar library
    4. Eclipse Indigo for Web Development
  2. Steps
    1. Configure your Eclipse for Apache CXF Webservice
    2. Import the ‘MyWebService’ Project in your eclipse Excel file content the embedded object Click here to get the Excel file Calling JAVA SOAP webservice from VBA
    3. Run the ‘TestPrintingInterfaceServer’ program in eclipse on Tomcat Server
    4. Run the ‘TestPrintingInterfaceClient’ program in eclipse to test the webservice is running or not
    5. Go in Excel VBA editor
    6. Consume the webservice
  3. Note
      1. Open Excel File.
      2. Press Alt+F11 button here to go in VBA editor.
      3. Create module ‘WebService_Module’
      4. Add the below code in that

    Option Explicit

    ‘Add Microsoft XML V6.0 library in reference
    Sub invoke_JAVA_SOAP_WebService()

    On Error GoTo ERROR_BLOCK

    Dim sURL As String
    Dim sEnv As String

    ‘Endpoint address
    sURL = “http://localhost:8020/MyWebService/services/TestPrintingPort”

    ‘SOAP envelope for submission to the Web Service
    sEnv = “
    sEnv = sEnv & “<soapenv:Envelope ” sEnv = sEnv & “xmlns:xsi=”””&#8221; ” sEnv = sEnv & “xmlns:xsd=”””&#8221; ” sEnv = sEnv & “xmlns:soapenv=””””>&#8221;
    sEnv = sEnv & ” ”
    sEnv = sEnv & ” ” ‘Java function name ‘ChangeCaseToUpper’ and ‘Target namespace’
    sEnv = sEnv & ” ganesh bhagat” ‘Function argument Name in webservice is ‘arg0’
    sEnv = sEnv & ” ”
    sEnv = sEnv & ” ”
    sEnv = sEnv & “”

    ‘Invoke a web service which requires authentication
    ‘ObjHTTP.Open “Post”, sURL, False, “username”, “password”

    ‘Invoke a web service which doesn’t require any user authentication
    ObjHTTP.Open “Post”, sURL, False

    ObjHTTP.setRequestHeader “Content-Type”, “text/xml”
    ObjHTTP.send (sEnv)

    Debug.Print ObjHTTP.responseText

    On Error Resume Next
    ‘clean up code
    Set ObjHTTP = Nothing
    Exit Sub

    Debug.Print Err.Description
    Resume EXIT_BLOCK
    End Sub