Hi,
it tried your example to call a web service from an HTML page. But the response text contains a message saying that the "SOAP Message is invalid". Do you have any idea what's wrong?
Best regards
Alex
Well I finally got time to try this out today and I have a solution.
I used Fiddler2 on the 2009 Sp1 VPC image to examine the SOAP envelope when the Web service is called from Visual Studio and compared this to the call made from within the HTML page.
The "real" content of the SOAP envelope was identical except my call included some Tabs and Spaces (things that should be ignored in the XML anyway). For some reason the SP1 version rejects this as an invalid SOAP message. Weird!
To get this working, change the setting of the SOAP envelope in the HTML page to:
var data = "";data += '<?xml version="1.0" encoding="utf-8"?>';data += '<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" ';data += 'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ';data += 'xmlns:xsd="http://www.w3.org/2001/XMLSchema">';data += '<soap:Body>';data += '<ConvertStrToUpperCase ';data += 'xmlns="urn:microsoft-dynamics-schemas/codeunit/NAV_Codeunit">';data += '<p_Str>hello nav2009!</p_Str>';data += '</ConvertStrToUpperCase>';data += '</soap:Body>';data += '</soap:Envelope>';
It's not as easy to read, but it works!
Eventually I'm going to write a little blog post about this and update the downloads so that there is a 2009 and 2009 SP1 version. In the meantime, this should give you enough information to get going again.
Dave.
Hi Alex,
which example are you doing? Did you try to key in the code or use the sample downloads. If you keyed it in, maybe you could send me your HTML file, if not let me know which file you are using.
Which version of NAV are you using NAV 2009 or NAV 2009 SP1. Are you using Internet Explorer to run the Web Page?
I'll send you an e-mail so you can reply with any files or attachments.
It's been a while since I did this example and I haven't tried it since SP1 was released.
Cheers,
I bought youre ebook implementing NAV.
In chapter 7, you write some examples to access NAV through Web services.
I found the page HelloNAV2009.htm, change the URL of the web service (mine is http://localhost:7047/DynamicsNAV/ws/CRONUS%20France%20S.A./Codeunit/NAV_Codeunit).
When i click the button "Call NAV", it returns me an error with the line containing "resultText = xmlDoc.getElementsByTagName("return_value")[0].childNodes[0].nodeValue;".
The error when executing this HTM page through Visual Studio 2008 is "Microsoft JScript Error : object is required".
did you have any idea of that ?
Thanks a lot.
Best regards,
Olivier.
Hi Olivier,
the error occurs because the "return_value" doesn't exist. Obviously Microsoft changed something inside the Web Service, so this example can't work properly (under SP1). We don't know exactly what they changed but I'm trying to discover (just as David does, I think...:-))
Hi Dave,
I have another question concerning the Web service. I'm trying to call the Web service from an Insert trigger inside the SQL server. Unfortunately the Web service says "Microsoft.Dynamics.Nav.Types.NavDatabasePasswordException" and "The user ID and password are invalid. Try again."
Do you have any idea how I could set the credentials to get it working?
The SQL code of the trigger is attached below this message.
Kind regards,
USE [Demo Database NAV (6-0)]GO
/****** Object: Trigger [dbo].[InsertTrigger] Script Date: 11/04/2009 11:07:13 ******/SET ANSI_NULLS ONGO
SET QUOTED_IDENTIFIER ONGO
CREATE TRIGGER [dbo].[InsertTrigger] ON [dbo].[Testtabelle] AFTER INSERTAS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for trigger here
DECLARE @hr intDECLARE @chrXML varchar (4000)DECLARE @chrLength nvarchar (8)SET @chrXML = '<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Body><ConvertStrToUpperCase xmlns="urn:microsoft-dynamics-schemas/codeunit/Test"><p_Str>hello nav2009!</p_Str></ConvertStrToUpperCase></soap:Body></soap:Envelope>'
SET @chrLength = LEN(@chrXML)
DECLARE @chrStatus nvarchar (4000)SET @chrStatus = ''
DECLARE @token int, @hdoc int, @xml varchar(8000)EXEC sp_OACreate 'WinHttp.WinHttpRequest.5.1', @token OUTEXEC sp_OAMethod @token, 'open', NULL, 'GET','http://localhost:7047/DynamicsNAV/WS/CRONUS AG/Codeunit/Test', falseEXEC sp_OAMethod @token, 'setRequestHeader', NULL, 'Content-Type', 'text/xml'EXEC xp_logevent 60000, @chrXMLEXEC @hr = sp_OAMethod @token, 'send', NULL, @chrXML
IF @hr < 0 BEGIN PRINT @hr EXEC @hr = sp_OAGetErrorInfo @tokenEND exec @hr = sp_OAGetProperty @token, 'status', @chrStatus OUTif @chrStatus <> 200 begin print @chrStatus END
EXEC xp_logevent 60000, @chrStatus
EXEC sp_OAMethod @token, 'responseText', @xml OUT
EXEC xp_logevent 60000, @xml
EXEC sp_OADestroy @token SELECT @xml
END
GO
I'm afraid I can't help you with this because it is not something I have ever done before. Maybe you should post the question on mibuso or dynanmicsuser.
As you probably know the browser example works because Internet Explorer handles the negotiation to use your credentials to call the web service. The way you are doing this in SQL Server is obviously not doing this.
I would question whether you should be trying to call a web service in an insert trigger on a SQL table. Beaer in mind that when you insert a record you typically want it to be fast and not to fail for some dependency on another system. You would be breaking both of these "rules" with what you are trying to do. If you are trying to do interfacing, maybe you should write values away to another table in the SQL trigger which will be fast and then have a scheduled job or other task written in .NET that processes the records and calls the Web service. I don't know what your DBAs are like but I can't imagine any I work with being happy to stick this kind of code into a production database.
Good luck with your task.