SOAP request

Torben_R.Torben_R. Member Posts: 99
I'm struggling with a SOAP request in NAV 5.0. I have to connect to a webshop where they use OpenBizBox.

The correct header for the request must look like this:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://some.shopdomain.com/soap.php"
xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body> etc.....

When I create it in NAV 5.0 the request is empty.

If I try this:
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:ns1="http://some.shopdomain.com/soap.php"
xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body> etc.....

I get a request that can be send but I get an error back - Version Mismatch

The difference is in the line xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/&quot; where only SOAP-ENC is accepted by the webshop and SOAP-ENV by NAV ](*,) ](*,) ](*,)

I have tried to leave out the line and a number of other things, but nothing seems to work.

Any good ideas?

Answers

  • ta5ta5 Member Posts: 1,164
    Hi Torben
    How do you create the Soap Request? Do you use MS XML 6.x?
    Regards
    Thomas
  • Torben_R.Torben_R. Member Posts: 99
    Yes.
      Name DataType Subtype XMLHttp Automation 'Microsoft XML, v6.0'.XMLHTTP60 XMLDomDoc Automation 'Microsoft XML, v6.0'.DOMDocument XMLDomNode Automation 'Microsoft XML, v6.0'.IXMLDOMNode CGBase64 Automation 'CG Request Client'.Base64 ADOStream Automation 'Microsoft ActiveX Data Objects 2.7 Library'.Stream
    XMLBody[1] := '<?xml version="1.0" encoding="utf-8"?>'+
               '<SOAP-ENV:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/" ' +
                                  'xmlns:ns1="' + Setup."Web Address" + '" ' +
                                  'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
                                  'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
                                  'xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" ' +
                                  'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' +
                 '<SOAP-ENV:Body>'+
                   '<ns1:OpenBizBox_XML>'+
                     '<param0 xsi:type="xsd:string">';
    
    ADOStream.LoadFromFile(TEMPORARYPATH + TempFile);
    XMLBody[2] := ADOStream.ReadText(1024);
    
    XMLBody[2] := DELSTR(XMLBody[2],1,STRLEN(ImportedString));
    
    XMLBody[3] :=    '</param0>' +
                   '</ns1:OpenBizBox_XML>' +
                 '</SOAP-ENV:Body>'+
               '</SOAP-ENV:Envelope>';
    
    ADOStream.Close;
    
    XMLDomDoc.loadXML(XMLBody[1] + XMLBody[2] + XMLBody[3]);
    XMLDomDoc.async:=FALSE;
    IF Setup."Save Request" THEN
      XMLDomDoc.save(Setup."Request File Name"); // For Test
    
    XMLHttp.open('POST',Setup."Web Address");
    XMLHttp.setRequestHeader('Content-Type','text/xml; charset=utf-8');
    XMLHttp.setRequestHeader('SOAPAction',Setup."Web Address" + '#OpenBizBox_XML');
    XMLHttp.send(XMLDomDoc.xml);
    XMLDomDoc.load(XMLHttp.responseXML);
    

    I have access to a testsite where I can enter and test the content of the envelope, see the complete request and see the result. The content is ok - the only problem (for now) is the SOAP-ENC/SOAP-ENV line in the request.
  • Torben_R.Torben_R. Member Posts: 99
    I have tested the same in NAV 2009 R2 with the same result.
  • ta5ta5 Member Posts: 1,164
    Hi
    Imo it's better not to add xml content combining parts with '+' like a text. Better use xmlDOMDoc to add the content. This way you have full control of the Document and if there is a problem normally you'll find out very soon.
    Try this:
    http://www.mibuso.com/dlinfo.asp?FileID=1384

    Anyway, what happens if you replace the 2. ENV by ENV? If you use a tool like xmlSpy, everything looks ok, no schema errors, etc.?
  • mdPartnerNLmdPartnerNL Member Posts: 802
    <?xml version="1.0" encoding="UTF-8"?>
    <SOAP-ENV:Envelope 
    	xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" 
    	xmlns:ns1="http://some.shopdomain.com/soap.php"
    	xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    	xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" 
    	SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>
    

    your SOAP-ENV was not created in the correct order. Use above.

    When I have problems with an xml, I save it and open it up in www.firstobject XML editor. Hope it helps.
  • ta5ta5 Member Posts: 1,164
    your SOAP-ENV was not created in the correct order. Use above.

    Thats what I mean. I you use xmlDomDoc to create, it's not possible to add "uneven" tags/elements, the document has to be well formed.
  • Torben_R.Torben_R. Member Posts: 99
    Hi guys. The structure is ok!!!!!!

    If I use ENV I can open the request in Internet Explorer.

    NAV will not create the request if I use ENC - and it has to be ENC
  • kinekine Member Posts: 12,562
    Torben R. wrote:
    Hi guys. The structure is ok!!!!!!

    If I use ENV I can open the request in Internet Explorer.

    NAV will not create the request if I use ENC - and it has to be ENC

    Have you used e.g. SOAPUI or Fiddler to catch the communication and the real message send to the server when using -ENC? It seems that you haven't changed the ENV for ENC everywhere where needed.
    Kamil Sacek
    MVP - Dynamics NAV
    My BLOG
    NAVERTICA a.s.
  • Torben_R.Torben_R. Member Posts: 99
    According to the description ENC is only used in one line and ENV in all the others. I have tried to use ENC in other lines as well without success.

    I save the request as a file before it's send.

    With ENC I get an empty file and with ENV a correct structured file.
Sign In or Register to comment.