Webservices, XML and special characters

RnR
Member Posts: 21
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?
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?
0
Answers
-
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...?0
-
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...0
-
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?0 -
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
Hope this helps you.
br
Kenneth0 -
Thnx Kenneth!
Since I'm processing an xml from another system in my vb.net code, this is how i solved it:
vb.netDim tempxml As String = Replace(xmlDoc.OuterXml.ToString, "utf-8", "ISO-8859-1")
Dyn 2009PostXml(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!0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions