Webservice 500 exception

bstapyltonbstapylton Member Posts: 34
edited 2009-02-25 in NAV Three Tier
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:
<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 :)

Answers

  • ara3nara3n Member Posts: 9,255
    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.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • bstapyltonbstapylton Member Posts: 34
    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.
  • ara3nara3n Member Posts: 9,255
    Np. Let me know how it goes. I don't think the source of the file should make a difference, but you never know.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • bstapyltonbstapylton Member Posts: 34
    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!
  • ara3nara3n Member Posts: 9,255
    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.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • bstapyltonbstapylton Member Posts: 34
    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
Sign In or Register to comment.