Subscribe to Depricated's Blog        RSS Feed

My Journey into Web Services with SOAP

Icon Leave Comment
So for the past few days I've been on a mission. About a month ago my boss asked me if we could use our in-house application (for which I'm the sole coder) to send updates to our ticketing system.

I explained that the ticketing system would need to be abe to receive the information, and I'd need to take a look to see what's possible. He got me with our team that handles the ticketing system, and they gave me the WSDLs used for its Web Services.

So we got SoapUI set up and I did some work with that til I understood what elements in the XML relate to which fields in the tickets. Made sure that my XML was sound and submitting before dropping it into the application.

But how the heck was I supposed to send the XML to the server, from the application? We're using SOAP so I did some digging around and reading. I'm using VBA, and it turns out Microsoft abandoned support for SOAP qua SOAP in 2005. Moreover, I found many instances of people saying that moving their application to Windows 7 broke its SOAP Functionality. I want to prevent that from ever being an issue, so I needed to find the best way to do this.

Some more digging and I discover what I need. I know any SOAP packages will fail in future updates. I found what I thought I needed, though: MSXML2

Before going on, I'll note that I was correct. It's what I'm using, though I tried several other packages between finding this one and accepting it. What I needed to do was create my SOAP Envelope - for this I used the XML that I verified working in SoapUI and coded it into its own function called CreateWorklogEnvelope. I chose to do it this way because the WSDL will not be changing, and so this is superior to accessing a file to get the XML out of it. Anyway...

It actually wound up being very simple and elegent to send the command, but actually finding HOW was the biggest pain in the rear.

The first thing I tried was using MSXML2.XMLHTTP40 to do a .Open and .Send. Access denied. I dug around to find what default headers are used to identify my request as a SOAP request to the server. Little luck. Finally, I'm poking around SoapUI when I find this little gem: THE DEBUGGER!

Duh. It should have seemed obvious. I ran my working XML, received a positive response, then went and checked the debugger to see what had been sent. And there were my headers! That was really the part that had me hung up on all of this - finding the headers that were needed.

The specifics I can't share, but I can share the structure of my code.

Sub SendWorklog()
    Dim soapURL As String
    Dim soapEnvelope As String
    Dim xmlhttp As New MSXML2.XMLHTTP40
    soapURL = "https://*.*.*/*/*?*=*&*=*"
    soapEnvelope = CreateWorklogEnvelope

    With xmlhttp
        .Open "POST", soapURL, False
        .setRequestHeader "Accept-encoding", "gzip,deflate"
        .setRequestHeader "Content-Type", "text/xml;charset=UTF-8"
        .setRequestHeader "SOAPAction", """**********"""
        .setRequestHeader "User-Agent", "********"
        .setRequestHeader "Host", "*.*.*"
        .setRequestHeader "Content-Length", Len(soapEnvelope)

        .Send soapEnvelope

        Debug.Print .responseText
    End With
End Sub

This works beautifully. CreateWorklogEnvelope simply returns your XML as a single string. Retrieve that however you please.

I mostly wanted to share the method of identifying what headers are needed. If you're able to submit via SoapUI, you should be able to pull the headers from the debugger in SoapUI. I'm excited to have figured this out on my own, having never previously touched SOAP or Web Services in my life. This made my day.

0 Comments On This Entry


Trackbacks for this entry [ Trackback URL ]

There are no Trackbacks for this entry

February 2017

19 202122232425

Recent Entries

Recent Comments

Search My Blog

0 user(s) viewing

0 Guests
0 member(s)
0 anonymous member(s)