XMLhttp.Send(xmlDoc) fails with error "Invalid at top level of document"
AronChan
Member Posts: 9
Im trying to send a xml file through http to a webservice.
Ive tested the webservice with SOAPUI and it works as intended with the same xml file as im trying to send with nav.
this is the code that im executing:
XmlDoc := XmlDoc;
IF ISCLEAR(XMLhttp) THEN //'Microsoft XML, v6.0'.XMLHTTP60
CREATE(XMLhttp, FALSE, TRUE);
IF ISCLEAR(XmlDoc) THEN BEGIN//'Microsoft XML, v6.0'.DOMDocument
CREATE(XmlDoc,FALSE,TRUE);
XmlDoc.loadXML(CreateSMS);
END;
XMLhttp.open('POST', 'Webservice adress', FALSE);
XMLhttp.setRequestHeader('Content-Type: ', 'Content-Type: text/xml');
XMLhttp.send(XmlDoc);
IF XMLhttp.status = 200 THEN BEGIN
IF (XMLhttp.responseText <> '') THEN BEGIN
END;
END ELSE BEGIN
ERROR('Status %1 %2',XMLhttp.status,XMLhttp.statusText);
END;
CLEAR(XmlDoc);
CLEAR(XMLhttp);
When debugging i can see that it fails at the line XMLhttp.send(XmlDoc); with the error message "Invalid at the top level of document" (translated from danish so it might be a bit different)
When using the SOUPUI to test the service i get the following response:
<response>
<stat>
<sendtime>17-03-2016 10:19:59</sendtime>
<buffered>1</buffered>
<received>0</received>
<rejected>0</rejected>
</stat>
<details>
<sendtime>17-03-2016 10:19:59</sendtime>
<batchid>46413721</batchid>
<state>DONE</state>
</details>
<status>201</status>
</response>
Can anybody give me directions as how to solve this issue?
Ive tested the webservice with SOAPUI and it works as intended with the same xml file as im trying to send with nav.
this is the code that im executing:
XmlDoc := XmlDoc;
IF ISCLEAR(XMLhttp) THEN //'Microsoft XML, v6.0'.XMLHTTP60
CREATE(XMLhttp, FALSE, TRUE);
IF ISCLEAR(XmlDoc) THEN BEGIN//'Microsoft XML, v6.0'.DOMDocument
CREATE(XmlDoc,FALSE,TRUE);
XmlDoc.loadXML(CreateSMS);
END;
XMLhttp.open('POST', 'Webservice adress', FALSE);
XMLhttp.setRequestHeader('Content-Type: ', 'Content-Type: text/xml');
XMLhttp.send(XmlDoc);
IF XMLhttp.status = 200 THEN BEGIN
IF (XMLhttp.responseText <> '') THEN BEGIN
END;
END ELSE BEGIN
ERROR('Status %1 %2',XMLhttp.status,XMLhttp.statusText);
END;
CLEAR(XmlDoc);
CLEAR(XMLhttp);
When debugging i can see that it fails at the line XMLhttp.send(XmlDoc); with the error message "Invalid at the top level of document" (translated from danish so it might be a bit different)
When using the SOUPUI to test the service i get the following response:
<response>
<stat>
<sendtime>17-03-2016 10:19:59</sendtime>
<buffered>1</buffered>
<received>0</received>
<rejected>0</rejected>
</stat>
<details>
<sendtime>17-03-2016 10:19:59</sendtime>
<batchid>46413721</batchid>
<state>DONE</state>
</details>
<status>201</status>
</response>
Can anybody give me directions as how to solve this issue?
0
Best Answer
-
Hey AronChan,
checkout this link if it helps you.
https://rockwithnav.wordpress.com/2016/02/23/consume-net-webservice-automation/Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/1
Answers
-
Hey AronChan,
checkout this link if it helps you.
https://rockwithnav.wordpress.com/2016/02/23/consume-net-webservice-automation/Thanks
Blog - rockwithnav.wordpress.com/
Twitter - https://twitter.com/RockwithNav
Facebook - https://facebook.com/rockwithnav/1 -
RockWithNAV wrote: »Hey AronChan,
checkout this link if it helps you.
https://rockwithnav.wordpress.com/2016/02/23/consume-net-webservice-automation/
It would seem that the .Send method didnt like my xmldoc variable. When i created the string manually it worked just fine. Thanks alot
0
Categories
- All Categories
- 75 General
- 75 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 610 NAV Courses, Exams & Certification
- 1.9K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 251 Dynamics CRM
- 103 Dynamics GP
- 6 Dynamics SL
- 1.5K Other
- 991 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 28 Design Patterns (General & Best Practices)
- Architectural Patterns
- 9 Design Patterns
- 4 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1K General Chat
- 1.6K Website
- 77 Testing
- 1.2K Download section
- 23 How Tos section
- 249 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
