Error 500 calling external web service from Navision

LnZ
Member Posts: 37
Hi I'm trying to call a simple web service that returns the uppercase of a string, but I always get Error 500 Internal Server Error.
Following are the Web Service XML and my Navision code
Any help would be appreciated
LnZ
--
Following are the Web Service XML and my Navision code
Any help would be appreciated
LnZ
--
POST /WSNAV/Service.asmx HTTP/1.1 Host: localhost Content-Type: text/xml; charset=utf-8 Content-Length: length SOAPAction: "http://tempuri.org/UpString" <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <UpString xmlns="http://tempuri.org"> <toUP>string</toUP> </UpString> </soap:Body> </soap:Envelope>Navision code
baseURL := 'http://localhost/WSNAV/Service.asmx/'; result := FALSE; URL := baseURL+'UpString'; method := 'UpString'; namespace := 'http://tempuri.org'; parameters := '<toUP>prova</toUP>'; // Create XML Document CREATE(xmldoc,TRUE,TRUE); // Create SOAP Envelope soapEnvelope := xmldoc.createElement('Soap:Envelope'); soapEnvelope.setAttribute('xmlns:Soap', 'http://schemas.xmlsoap.org/soap/envelope/'); xmldoc.appendChild(soapEnvelope); // Create SOAP Body soapBody := xmldoc.createElement('Soap:Body'); soapEnvelope.appendChild(soapBody); // Create Method Element soapMethod := xmldoc.createElement(method); soapMethod.setAttribute('xmlns', namespace); soapBody.appendChild(soapMethod); // Transfer parameters by loading them into a XML Document and move them CREATE(parametersXmlDoc,TRUE,TRUE); parametersXmlDoc.loadXML('<parameters>'+parameters+'</parameters>'); IF parametersXmlDoc.firstChild.hasChildNodes THEN BEGIN WHILE parametersXmlDoc.firstChild.childNodes.length>0 DO BEGIN node := parametersXmlDoc.firstChild.firstChild; node := parametersXmlDoc.firstChild.removeChild(node); soapMethod.appendChild(node); END; END; // Create XMLHTTP and SEND CREATE(xmlhttp, TRUE, TRUE); xmlhttp.open('POST', URL, FALSE); xmlhttp.setRequestHeader('Content-type', 'text/xml; charset=utf-8'); xmlhttp.setRequestHeader('SOAPAction', method); xmlhttp.send(xmldoc); // If status is OK - Get Result XML IF xmlhttp.status=200 THEN BEGIN xmldoc := xmlhttp.responseXML; xmldoc.setProperty('SelectionLanguage','XPath'); xmldoc.setProperty('SelectionNamespaces','xmlns:tns="'+namespace+'"'); //How I can read the result?? result := TRUE; END ELSE BEGIN MESSAGE(FORMAT(xmlhttp.status)); MESSAGE(FORMAT(xmlhttp.statusText)); MESSAGE(FORMAT(xmlhttp.responseText)); END;
0
Answers
-
I have seen that if I call a web service without parameters everything works, Still have no idea on what is wrong in the parameters I pass to the web service.
LnZ0 -
The way you transfer the parameters seems wrong - the function you are calling is taking a string - that's what you should give it (not an XML structure under <parameters>.
I have a sample on my blog on how to call NAV Web Services from NAV - maybe that can help
http://blogs.msdn.com/freddyk/archive/2010/01/22/connecting-to-nav-web-services-from-microsoft-dynamics-nav-2009-sp1.aspxFreddy Kristiansen
Group Program Manager, Client
Microsoft Dynamics NAV
http://blogs.msdn.com/freddyk
The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.0 -
That's true, looking a the POST method definition of the webservice I have seen this
POST /WSNAV/Service.asmx/UpString HTTP/1.1 Host: localhost Content-Type: application/x-www-form-urlencoded Content-Length: length toUP=string
But I' dont know how to pass this parameter as string, sorry but I'm a newbie ath this type of things
Thank You
LnZ0 -
Hi,
I have changed my code to pass parameters as string but I still get the same error,If I copy and paste my generated xml into SoapUI it works fine.
It seems a client problem of my navision function.
The exact error I get is this Error 500: System.InvalidOperationException: Request format is invalid
This is my xml for the call:<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"> <soap:Header/> <soap:Body> <UpString xmlns="http://tempuri.org"> <toUP>prova</toUP> </UpString> </soap:Body> </soap:Envelope>
And this is my new code:baseURL := 'http://localhost/WSNAV/Service.asmx/'; result := FALSE; URL := baseURL+'UpString'; method := 'UpString'; namespace := 'http://tempuri.org'; // Create XML Document CREATE(xmldoc,TRUE,TRUE); // Create SOAP Envelope soapEnvelope := xmldoc.createElement('soap:Envelope'); soapEnvelope.setAttribute('xmlns:soap', 'http://www.w3.org/2003/05/soap-envelope'); xmldoc.appendChild(soapEnvelope); soapHeader := xmldoc.createElement('soap:Header'); soapEnvelope.appendChild(soapHeader); // Create SOAP Body soapBody := xmldoc.createElement('soap:Body'); soapParameters:= xmldoc.createElement('toUP'); soapParameters.text := 'prova'; soapEnvelope.appendChild(soapBody); // Create Method Element soapMethod := xmldoc.createElement(method); soapMethod.setAttribute('xmlns', namespace); soapMethod.appendChild(soapParameters); soapBody.appendChild(soapMethod); // Transfer parameters by loading them into a XML Document and move them // Create XMLHTTP and SEND CREATE(xmlhttp, TRUE, TRUE); xmlhttp.open('POST', URL, FALSE); xmlhttp.setRequestHeader('Content-type', 'application/soap+xml; charset=UTF-8'); xmlhttp.setRequestHeader('Content-Length',FORMAT(STRLEN(xmldoc.xml))); MESSAGE(FORMAT(STRLEN(xmldoc.xml))); xmlhttp.setRequestHeader('SOAPAction', method); // If status is OK - Get Result XML IF xmlhttp.status=200 THEN BEGIN xmldoc := xmlhttp.responseXML; xmldoc.setProperty('SelectionLanguage','XPath'); xmldoc.setProperty('SelectionNamespaces','xmlns:tns="'+namespace+'"'); result := TRUE; END ELSE BEGIN MESSAGE(FORMAT(xmlhttp.status)); MESSAGE(FORMAT(xmlhttp.statusText)); MESSAGE(FORMAT(xmlhttp.responseText)); END;
Any Idea?
LnZ0 -
Solved, it was a problem on the soap definition, the other developer chganged the namespace without advising me.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