Options

Save a SOAP message to XML

ta5ta5 Member Posts: 1,164
Hello

Based on this post

viewtopic.php?t=24825

I came to the conclusion, that I will be better for debugging and logging purposes to save all outgoing soap messages to xml.

With *incoming* SOAP-Messages it works like this:
CREATE(XMLDom);
XMLDom.async := FALSE;
XMLDom.load(SoapHttpConn.OutputStream);
XMLDom.save('c:\something.xml');

Does anybody know how to save *outgoing* soap messages to xml before they are sent to the webservice?

This is a part of the code how the message is sent:
SoapSerialize.StartElement('param');
..
SoapSerialize.EndElement;
SoapSerialize.EndBody;
SoapSerialize.EndEnvelope;
SoapHttpConn.EndMessage;

Many thanks in adance.
Thomas

Answers

  • Options
    rvduurenrvduuren Member Posts: 92
    Hello Thomas,

    Here's a simple out of the box working solution..

    http://www.mibuso.com/forum/viewtopic.p ... 952#110952
    Met vriendelijke groet, best regards,

    Rvduuren
  • Options
    ta5ta5 Member Posts: 1,164
    Hi Rvduuren
    Thanks for replying. I can see the part where you save the soap response, but I can't find the part where you save the soap request (the message that is beeing sent to the webservice). Am I blind? :?

    Thanks in advance
    Thomas
  • Options
    ara3nara3n Member Posts: 9,255
    The xml file should like this.
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ec.europa.eu:taxud:vies:services:checkVat:types">
       <soapenv:Header/>
       <soapenv:Body>
          <urn:checkVat>
             <countryCode>?</countryCode>
             <vatNumber>?</vatNumber>
          </urn:checkVat>
       </soapenv:Body>
    </soapenv:Envelope>
    

    I usually do not use SOAP Microsoft Soap Type Library, but xmlHTTP automation, and create the xml using xmlport.

    Here is an example

    http://mibuso.com/blogs/ara3n/2008/03/0 ... -navision/
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    ara3nara3n Member Posts: 9,255
    BTW I use soapUI program to connect to webservices and see all the request and how the xml file should look like.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    ta5ta5 Member Posts: 1,164
    ara3n wrote:
    BTW I use soapUI program to connect to webservices and see all the request and how the xml file should look like.

    Thanks for your valuable post on this. With soapUI I was able to see how the XML should look like. Very helpful as everybody who has ever seen a complex wsdl file probably would confirm.

    Anyway, is it possible to save the outgoing soap from the navision client? I actually cannot imagine why it doesnt work, particulary because saving the incoming soap is just that simple ](*,)

    Regards
    Thomas
  • Options
    ara3nara3n Member Posts: 9,255
    To see the xml file, you need to direct the soapserialize to a different location


    MyFile.CREATE('c:\xml2.xml');
    MyFile.CREATEINSTREAM(Istream);
    Serializer.Init(Istream);
    
    //t Serializer.Init(Connector.InputStream);
    
    
    Serializer.startEnvelope('','STANDARD','utf-16');
    Serializer.startBody('STANDARD');
    Serializer.startElement('checkVat','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
    
      Serializer.startElement('countryCode','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
      Serializer.writeString('GB');
      Serializer.endElement;
      Serializer.startElement('vatNumber','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
      Serializer.writeString('704767477');
      Serializer.endElement;
    
    Serializer.endElement;
    Serializer.endBody;
    
    Serializer.endEnvelope;
    
    
    MyFile.CLOSE;
    
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    ta5ta5 Member Posts: 1,164
    Hi Rashed

    Thanks for the code, very much appreciated! Unfortunately the file is still empty after running that code. We are using Navision 3.7, soap3.0

    Does it work on your installation?
    Regards and thanks in advance
    Thomas
    CREATE(Serializer);
    
    MyFile.CREATE('c:\temp\file2.xml');
    MyFile.CREATEINSTREAM(myInstream);
    Serializer.Init(myInstream);
    
    Serializer.StartEnvelope('','STANDARD','utf-16'); 
    Serializer.StartBody('STANDARD'); 
    Serializer.StartElement('checkVat','urn:ec.europa.eu:taxud:vies:services:checkVat:types'); 
      Serializer.StartElement('countryCode','urn:ec.europa.eu:taxud:vies:services:checkVat:types'); 
      Serializer.WriteString('GB'); 
      Serializer.EndElement; 
      Serializer.StartElement('vatNumber','urn:ec.europa.eu:taxud:vies:services:checkVat:types'); 
      Serializer.WriteString('704767477'); 
      Serializer.EndElement; 
    Serializer.EndElement; 
    Serializer.EndBody; 
    Serializer.EndEnvelope; 
    
    MyFile.CLOSE;
    
  • Options
    ara3nara3n Member Posts: 9,255
    Yes it works in my example

    I use Microsoft Soap Type Library V1 in 5.0 exe.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    ajhvdbajhvdb Member Posts: 672
    ara3n wrote:
    To see the xml file, you need to direct the soapserialize to a different location


    MyFile.CREATE('c:\xml2.xml');
    MyFile.CREATEINSTREAM(Istream);
    Serializer.Init(Istream);
    
    //t Serializer.Init(Connector.InputStream);
    
    
    Serializer.startEnvelope('','STANDARD','utf-16');
    Serializer.startBody('STANDARD');
    Serializer.startElement('checkVat','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
    
      Serializer.startElement('countryCode','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
      Serializer.writeString('GB');
      Serializer.endElement;
      Serializer.startElement('vatNumber','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
      Serializer.writeString('704767477');
      Serializer.endElement;
    
    Serializer.endElement;
    Serializer.endBody;
    
    Serializer.endEnvelope;
    
    
    MyFile.CLOSE;
    

    Interesting topic :-k

    What are these functions?
    Serializer.endElement;
    Serializer.startElement
  • Options
    ara3nara3n Member Posts: 9,255
    It's Microsoft Soap Type Library with serializer class.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    ajhvdbajhvdb Member Posts: 672
    Thx, just tried using it...and understanding..Nice

    Are there more code examples?
  • Options
    ara3nara3n Member Posts: 9,255
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    ajhvdbajhvdb Member Posts: 672
    Yes, I've reread that one too .. and in there removal of namespace!, xlt files!, saving into the blob!, I understand it a little bit more now and will start by creating a webservice for a small webshop.

    It was thinking of doing this with a simple import/export but this looks to be the future of things to come. It all looks so complicated with all those definitions.
  • Options
    ara3nara3n Member Posts: 9,255
    Yes web services is will be used a lot in the future. Here is another blog on how to use it

    http://mibuso.com/blogs/ara3n
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    ta5ta5 Member Posts: 1,164
    I just gave it antother try this morning. It still does not work but what is kind of interesting that Nav 3.7 client crashes if "message" or "sleep" is used in the code.

    Thomas
  • Options
    ajhvdbajhvdb Member Posts: 672
    Can't you save your xml file first. Then use SoapUI to send and debug it? It will give you much more info then NAV.
  • Options
    ta5ta5 Member Posts: 1,164
    ajhvdb wrote:
    Can't you save your xml file first. Then use SoapUI to send and debug it? It will give you much more info then NAV.

    Hmm, sounds interesting, do you have an example (pseudocode is ok)?
  • Options
    ajhvdbajhvdb Member Posts: 672
    Isn't that the code from Rashed.
  • Options
    ara3nara3n Member Posts: 9,255
    Download the 5.0 sp1 from mibuso download section and try your code in it. See if you get the result.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Options
    ta5ta5 Member Posts: 1,164
    ara3n wrote:
    Download the 5.0 sp1 from mibuso download section and try your code in it. See if you get the result.


    Bingo! \:D/ It works with 5.0 and 5.0 SP1, but not with 3.7! Since the installation in question will upgrade to 5.0 anyway this is ok for us.
    Thanks for all your help, espacially to Rashed.

    Thomas
  • Options
    ara3nara3n Member Posts: 9,255
    You are welcome, and good luck.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
Sign In or Register to comment.