Webservice 500 exception

bstapylton
Member Posts: 34
Hi guys,
I've had a bit of trouble calling a webservice using XMLport/Codeunit combo in NAV 2009. Basically I'm getting a status 500 (Internal Server Error).
I followed this guide to make my code and SOAP request:
viewtopic.php?f=5&t=23618
My webservice is in SQL Server 2005 running on Windows Server 2008; very simple - takes a single parameter and returns a single value.
NAV is running on a VPC instance from the Server 2008 machine.
For debugging I downloaded soapUI and it generated this soap code for me:
If I fill "?" with a valid number it will run the stored procedure in SQL Server and return me my answer - so I'm very content with the enpoint and the execution of the web service on the server end.
Next thing I did was to alter my XMLPort object so that it produced an xml document identical to my soapUI request. I've confirmed in the XMLRequest.txt file that this is the case, both requests are identical from what I can see.
So if it's not a problem with the server... why this "Internal Server Error"?
Here is the SendMessage part of the code (link above) which I have modified a little to get it this far:
Here is the code that creates the endpoint if it helps.
Thanks in advance for any help
I've had a bit of trouble calling a webservice using XMLport/Codeunit combo in NAV 2009. Basically I'm getting a status 500 (Internal Server Error).
I followed this guide to make my code and SOAP request:
viewtopic.php?f=5&t=23618
My webservice is in SQL Server 2005 running on Windows Server 2008; very simple - takes a single parameter and returns a single value.
NAV is running on a VPC instance from the Server 2008 machine.
For debugging I downloaded soapUI and it generated this soap code for me:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:cus="http://sqlserver/customer"> <soapenv:Header/> <soapenv:Body> <cus:GetLuckyNumber> <cus:customerID>?</cus:customerID> </cus:GetLuckyNumber> </soapenv:Body> </soapenv:Envelope>
If I fill "?" with a valid number it will run the stored procedure in SQL Server and return me my answer - so I'm very content with the enpoint and the execution of the web service on the server end.
Next thing I did was to alter my XMLPort object so that it produced an xml document identical to my soapUI request. I've confirmed in the XMLRequest.txt file that this is the case, both requests are identical from what I can see.
So if it's not a problem with the server... why this "Internal Server Error"?
Here is the SendMessage part of the code (link above) which I have modified a little to get it this far:
//setup the temporary table so that we can handle the XML without saving it to disk first //create a couple of streams to transfer the data in and out of the BLOB field CLEAR(TempTable); TempTable.Blob.CREATEINSTREAM(InStr); TempTable.Blob.CREATEOUTSTREAM(OutStr); //the request XMLport fills the BLOB with the XML message CLEAR(XP1); // BMS 20/02/2009 - Set the CustomerID. XP1.AssignCustomerID(lvarCustID); XP1.SETDESTINATION(OutStr); XP1.EXPORT; //load the message into the XML automation variable IF ISCLEAR(XMLDoc) THEN CREATE(XMLDoc); XMLDoc.load(InStr); //this is for diagnostics only, so you can see what the XMLport actually produced XMLDoc.save('C:\Temp\XMLRequest.txt'); //create the HTTP connector IF ISCLEAR(XMLHttpConn) THEN CREATE(XMLHttpConn); //tell it where the web service is located XMLHttpConn.open('POST','http://sqlserver/sql',FALSE, 'username', 'password'); //set some values in the request header depending on what the service requires XMLHttpConn.setRequestHeader('Host','sqlserver'); XMLHttpConn.setRequestHeader('SOAPAction','http://sqlserver/customerGetLuckyNumber'); XMLHttpConn.setRequestHeader('Content-type','text/xml;charset=UTF-8'); XMLHttpConn.setRequestHeader('Content-Length','299'); //actually send the message XMLHttpConn.send(XMLDoc); //get the response XMLDoc.load(XMLHttpConn.responseXML); //tell us if we got an error (it is 200 because the response definition said "200 OK") IF XMLHttpConn.status <> 200 THEN BEGIN MESSAGE('Status %1 %2',XMLHttpConn.status,XMLHttpConn.statusText); EXIT; END; //this is for diagnostics only, so you can see what you got back XMLDoc.save('C:\Temp\XMLResponse1.xml'); //take away the namespaces RemoveNamespace(XMLDoc,XMLDoc); //this is for diagnostics only, so you can see what it looks like after the namespaces have gone XMLDoc.save('C:\Temp\XMLResponse2.xml'); //fill the BLOB with the response XML XMLDoc.save(OutStr); //the response XMLport reads the data from the BLOB and processes it CLEAR(XP2); XP2.SETSOURCE(InStr); XP2.IMPORT;
Here is the code that creates the endpoint if it helps.
DROP ENDPOINT sql_CustomerLuckyNumber; GO CREATE ENDPOINT sql_CustomerLuckyNumber STATE = STARTED AS HTTP( PATH = '/sql', AUTHENTICATION = ( INTEGRATED ), PORTS = ( CLEAR ), SITE = '*' ) FOR SOAP ( WEBMETHOD 'http://sqlserver/customer'.'GetLuckyNumber' (name='OPAL.dbo.GetCustomerLuckyNumber', SCHEMA=STANDARD ), WSDL = DEFAULT, SCHEMA = STANDARD, DATABASE = 'OPAL', NAMESPACE = 'http://sqlserver/customer/' ); GO
Thanks in advance for any help

0
Answers
-
Have you looked at this post?
http://mibuso.com/blogs/ara3n/2008/05/1 ... bservices/
It shows you how to consume an endpoint webservice in nav. Hope this helps.0 -
This looks interesting. You have your SOAP xml already written to a file on the hdd? In my solution I use an XMLPort to create the xml, but then most of the remainder of your code looks the same as mine for the most part.
I am back at work tomorrow so I will give it a try then, thanks.0 -
Np. Let me know how it goes. I don't think the source of the file should make a difference, but you never know.0
-
Wow what a stupid error on my part!
I implemented your code, ara3n, and it more-or-less worked right away. So then I looked at where yours was different to mine, when I came across this:XmlHttp.SetRequestHeader('SOAPAction','"http://Navision-5/EmployeeEmployeeList"');
The double quotes inside the namespace! That sorted it right out. Now I have to try and sort out pulling just the answer from all this XML hehe.
Thanks!0 -
You are welcome. Instead of adding [solved] to the subject, there is a new option on the subject that allows you to select solved. I think that's how they want to differentiate solved threads.0
-
ara3n wrote:You are welcome. Instead of adding [solved] to the subject, there is a new option on the subject that allows you to select solved. I think that's how they want to differentiate solved threads.
Ahh so there is. I have run into another problem in the meantime, but since technically this issue is solved and my problem, although related, is another issue, I should probably go and make another thread. Hopefully this one can be solved as well!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