Webservices, XML and special characters

RnRRnR Member Posts: 21
edited 2010-06-24 in NAV Three Tier
I've just converted to 2009 and can't believe how hard it is to use the new fancy webservice layer. It's amazing how easy it is to create a new codeunit and publish a service, but everything else disappoints me.

My scenario:

1. A function in a codeunit has bigtext as input parameter and this is published as a webservice.
2. I'm using vb.net to send in a huge xml file (standard in another system) into the webservice
3. To be able to get the content in the bigtext input into an XMLDomDoc, I have to save the content (xml) to a file --> read the file into an adoInStream with a charset of iso-8859-1, create an adoOutStream with a charset of utf-8 and read the file into the adoOutStream. Then i save the file again before i read the content into an XMLDomDoc.
4. Puh, no I'm finally able to get the nodes I need and save the data into Dynamics Nav 2009.

BUT, all special characters (like æøå) is converted to '>'.

Is it really this hard to create a webservice which takes an xml as input and be able to read the contents of it?

Not the most agile solution :(

Have any of you successfully imported a custom xml into Dynamics Nav 2009 through webservices?

Answers

  • AdrianAkersAdrianAkers Member Posts: 137
    Why don't you get your VB.net code to save the XML file and then return the filepath to the XML file to NAV thorugh the webservices. Then in NAV loading the XML file is much much easier...? :)
  • RnRRnR Member Posts: 21
    the vb.net app is actually a web app which will be installed on multiple servers within our organisation. forcing applications to be run from the same server / have access to fileshares is not in line with agile solutions...
  • AdrianAkersAdrianAkers Member Posts: 137
    Ok, can see the problem with the proposed solution now I have a bit more information!

    Why don't you write a custom webservice in your asp.net app to accept an XML doc as a parameter and then update the NAV database from within this custom webservice, then you need to do minimal on the NAV side?
  • TennekTennek Member Posts: 11
    Maybe this will help you. Remember this is just sample code I made (C# - easy to convert to VB):
    XmlDocument XMLDoc = new XmlDocument();
                XMLDoc.Load("C:\\NAV.xml");
                XmlNode Node = XMLDoc.FirstChild;
                if (Node.NodeType  == XmlNodeType.XmlDeclaration) {
                    XmlDeclaration XMLDecl = XMLDoc.CreateXmlDeclaration("1.0", null, null);
                    XMLDecl.Encoding = "ISO-8859-1";
                    XMLDoc.ReplaceChild(XMLDecl, Node);
                    XMLDoc.Save("C:\\NAV2.xml");                
                }
                string data = XMLDoc.OuterXml;
    
    I think this is abouth same as you are doing. The main point is to set the encoding to "ISO-8859-1".

    Next you need to convert the BigText with C/AL. looping through the BigText and convert fra ascii to ansi:
    Position := 1;
    count := 1;
    WHILE count <> 0 DO BEGIN
      count := XML.GETSUBTEXT(Str,Position, 250);
      IF Str <> '' THEN BEGIN
        Str := Ascii2Ansi(Str);
        Bstr.ADDTEXT(Str);
        CLEAR(Str);
      END;
      Position += 250;
    END;
    
    Bstr.WRITE(OutStream1);
    

    Then you can use a XMLport to process the BigText(xml file) or what ever you want to do with it :wink:
    Hope this helps you.

    br
    Kenneth
  • RnRRnR Member Posts: 21
    Thnx Kenneth!

    Since I'm processing an xml from another system in my vb.net code, this is how i solved it:

    vb.net
    Dim tempxml As String = Replace(xmlDoc.OuterXml.ToString, "utf-8", "ISO-8859-1")
    

    Dyn 2009
    PostXml(XmlStr : BigText) RetStr : Text[250]
    
    Position := 1;
    Count := 1;
    WHILE Count <> 0 DO BEGIN
      Count := XmlStr.GETSUBTEXT(Str,Position, 250);
      IF Str <> '' THEN BEGIN
        Str := cu_Tools.Ascii2Ansi(Str);
        Bstr.ADDTEXT(Str);
        CLEAR(Str);
      END;
      Position += 250;
    END;
    
    r_XMLimp.INIT;
    r_XMLimp.CALCFIELDS(Blob);
    r_XMLimp.Blob.CREATEOUTSTREAM(StreamOut);
    Bstr.WRITE(StreamOut);
    r_XMLimp.INSERT;
    

    The blob looks nice and my problem is solved.

    You made my day K!
Sign In or Register to comment.