Archived Forum Post

Index of archived forum posts

Question:

Soap envelope [VB.NET]

Jun 06 '14 at 08:07

Hello everyone, I call a webservice to send a zip file and I need to send a soap envelope, as I ignore how to make an envelope, I used this code. The envelope i've to generate looks like this one:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://service.sunat.gob.pe" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <soapenv:Header>
    <wsse:Security> 
    <wsse:UsernameToken> 
    <wsse:Username>20100066603MODDATOS</wsse:Username>
    <wsse:Password>moddatos</wsse:Password> 
    </wsse:UsernameToken> 
    </wsse:Security> 
    </soapenv:Header>
    <soapenv:Body> 
    <ser:sendBill> 
    <fileName>20100066603-01-F001-1.zip</fileName>
    <contentFile>cid:20100066603-01-F001-1.zip</contentFile>
    </ser:sendBill> 
    </soapenv:Body>
    </soapenv:Envelope>

I've tried to generate it like this:

Dim soapReq As New Chilkat.Xml
    soapReq.Encoding = "utf-8"
    soapReq.Tag = "soapenv:Envelope"
    soapReq.AddAttribute("xmlns:soapenv", "http://schemas.xmlsoap.org/soap/envelope/")
    soapReq.AddAttribute("xmlns:ser", "http://service.sunat.gob.pe")
    soapReq.AddAttribute("xmlns:wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd")

    soapReq.NewChild2("soapenv:Header", "")
    soapReq.NewChild2("soapenv:Body", "")
    soapReq.FirstChild2()
    soapReq.NewChild2("wsse:Security", "")
    soapReq.FirstChild2()
    soapReq.NewChild2("wsse:UsernameToken", "")
    soapReq.FirstChild2()
    soapReq.NewChild2("wsse:Username", "20100066603MODDATOS")
    soapReq.NewChild2("wsse:Password", "moddatos")
    soapReq.GetRoot2()
    soapReq.GetParent2()
    soapReq.NewChild2("ser:SendBill", "")
    soapReq.FirstChild2()
    soapReq.NewChild2("FileName", "20100066603-01-F001-1.zip")
    soapReq.NewChild2("contentFile", "cid:20100066603-01-F001-1.zip")
    soapReq.GetRoot2()

but it's a fail. How shall I proceed? Thanks


Answer

This call sequence makes no sense:

    soapReq.GetRoot2()
    soapReq.GetParent2()
Once you've moved to the root node in the XML document, it has no parent (because it's the root) and therefore the call to GetParent2 does nothing.

It seems you were trying to navigate to the "soapenv:Body" node, so that the code that follows can construct that part of the document. To navigate to "soapenv::Body", you would:

    soapReq.GetRoot2()
    soapReq.FindChild2("soapenv::Body")