mibuso.com

Microsoft Business Solutions online community
It is currently Sun May 26, 2013 2:07 am

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: [Solved] Webservice 500 exception
PostPosted: Mon Feb 23, 2009 7:28 am 
Offline

Joined: Mon Feb 23, 2009 7:11 am
Posts: 26
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:
Code: Select all
<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:


Code: Select all
//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.


Code: Select all
   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 :)


Last edited by bstapylton on Wed Feb 25, 2009 5:30 am, edited 2 times in total.

Top
 Profile E-mail  
 
 Post subject: Re: Webservice 500 exception
PostPosted: Mon Feb 23, 2009 9:04 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Wed Dec 15, 2004 6:11 pm
Posts: 8704
Location: 3rd rock from sun
Country: United States (us)
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.

_________________
Rashed.

blog: http://mibuso.com/blogs/ara3n/


Top
 Profile  
 
 Post subject: Re: Webservice 500 exception
PostPosted: Tue Feb 24, 2009 3:56 am 
Offline

Joined: Mon Feb 23, 2009 7:11 am
Posts: 26
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.


Top
 Profile E-mail  
 
 Post subject: Re: Webservice 500 exception
PostPosted: Tue Feb 24, 2009 8:39 pm 
Offline
MVP Microsoft Dynamics NAV

Joined: Wed Dec 15, 2004 6:11 pm
Posts: 8704
Location: 3rd rock from sun
Country: United States (us)
Np. Let me know how it goes. I don't think the source of the file should make a difference, but you never know.

_________________
Rashed.

blog: http://mibuso.com/blogs/ara3n/


Top
 Profile  
 
 Post subject: Re: Webservice 500 exception
PostPosted: Wed Feb 25, 2009 1:08 am 
Offline

Joined: Mon Feb 23, 2009 7:11 am
Posts: 26
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:

Code: Select all
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!


Top
 Profile E-mail  
 
 Post subject: Re: [SOLVED] Webservice 500 exception
PostPosted: Wed Feb 25, 2009 5:01 am 
Offline
MVP Microsoft Dynamics NAV

Joined: Wed Dec 15, 2004 6:11 pm
Posts: 8704
Location: 3rd rock from sun
Country: United States (us)
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.

_________________
Rashed.

blog: http://mibuso.com/blogs/ara3n/


Top
 Profile  
 
 Post subject: Re: [SOLVED] Webservice 500 exception
PostPosted: Wed Feb 25, 2009 5:31 am 
Offline

Joined: Mon Feb 23, 2009 7:11 am
Posts: 26
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! :D


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum


Search for:
Jump to: