Web Service paramater

ClausHamann
Member Posts: 80
Hi
I have created a simple NAV 2009 web service codeunit (My Web Service) and a codeunit (Call Web Service) that calls this web service as shown below. My problem is I can't get the MyMessage parameter in ShowMessage passed to the web services (Input.xml for how I am passing the parameter).
I get this error when I run the web service (codeunit 51101 Call Web Service).
Parameter myMessage in method ShowMessage in service MyWebService is null!
Does anybnody know how to pass the parameter to the web service?
Thanks
Claus
My Web Service:
Call Web Service:
C:\Input.xml
I have created a simple NAV 2009 web service codeunit (My Web Service) and a codeunit (Call Web Service) that calls this web service as shown below. My problem is I can't get the MyMessage parameter in ShowMessage passed to the web services (Input.xml for how I am passing the parameter).
I get this error when I run the web service (codeunit 51101 Call Web Service).
Parameter myMessage in method ShowMessage in service MyWebService is null!
Does anybnody know how to pass the parameter to the web service?
Thanks
Claus
My Web Service:
ShowMessage(MyMessage : Text[30]) outputtext : Text[30] EXIT(MyMessage);
Call Web Service:
OnRun() CREATE(XMLDoc); CREATE(XMLDoc2); XMLDoc.async := FALSE; XMLDoc.load('C:\Input.xml'); CREATE(XMLHTTP); XMLHTTP.open('POST','http://localhost:7047/DynamicsNAV/WS/CRONUS_New_Zealand_Ltd/Codeunit/MyWebService',0); XMLHTTP.setRequestHeader('Content-type','text/xml'); XMLHTTP.setRequestHeader('SOAPAction', 'http://localhost:7047/DynamicsNAV/WS/CRONUS_New_Zealand_Ltd/Codeunit/MyWebService:ShowMessage'); XMLHTTP.send(XMLDoc); XMLDoc2.load(XMLHTTP.responseXML); XMLDoc2.save('C:\Output.xml'); FoundXMLNode := XMLDoc2.selectSingleNode('Soap:Envelope/Soap:Body/MyWebService_Result/return_value'); IF XMLHTTP.status = 200 THEN BEGIN IF ISCLEAR(FoundXMLNode) THEN MESSAGE('NOT FOUND') ELSE MESSAGE('%1',FoundXMLNode.text) END ELSE MESSAGE('%1',XMLHTTP.responseText);
C:\Input.xml
<?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 > <ShowMessage xmlns="http://localhost:7047/DynamicsNAV/WS/CRONUS_New_Zealand_Ltd/Codeunit/MyWebService"> <MyMessage>This is a Test</MyMessage> </ShowMessage> </soap:Body> </soap:Envelope>
0
Answers
-
Can you paste you NAV function that you've published as webservice?
thanks.0 -
Hi arn3n
The NAV function I have published as a webservice is the ShowMessage in the My Web Service codeunit.
My Web Service:ShowMessage(MyMessage : Text[30]) outputtext : Text[30] EXIT(MyMessage);
The full codeunit looks like this:
OBJECT Codeunit 51102 My Web Service
{
OBJECT-PROPERTIES
{
Date=07/05/09;
Time=13:42:11;
Modified=Yes;
Version List=;
}
PROPERTIES
{
OnRun=BEGIN
END;
}
CODE
{
PROCEDURE ShowMessage@1000000001(MyMessage@1000000000 : Text[30]) outputtext : Text[30];
BEGIN
EXIT(MyMessage);
END;
BEGIN
END.
}
}
I can run the webservice if I remove the parameter MyMessage in the ShowMessage functions and replaces the variable with a plain text.
Regards
Claus0 -
your input.xml file need to look like this. You don't need to create an xml file and then use MSDom to load it. Create a text variable and assign this text. Then call xmlhttp.set(mytextvariable);
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="urn:microsoft-dynamics-schemas/codeunit/WS"> <soapenv:Header/> <soapenv:Body> <ws:ShowMessage> <ws:myMessage>Hello World</ws:myMessage> </ws:ShowMessage> </soapenv:Body> </soapenv:Envelope>
0 -
Thanks arn3n
I tried to change the input.xml file to your suggestion but I am still getting the same error.
Do you have any other suggestions?
Regards
Claus
Microsoft Dynamics NAV Classic
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="urn:microsoft-dynamics-schemas/error">a:Microsoft.Dynamics.Nav.Service.WebServices.ServiceBrokerException</faultcode><faultstring xml:lang="en-NZ">Parameter myMessage in method ShowMessage in service MyWebService is null! </faultstring><detail><string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Parameter myMessage in method ShowMessage in service MyWebService is null! </string></detail></s:Fault></s:Body></s:Envelope>
OK
0 -
Hi arn3n
I have tried to replicate the code in Visual Studio but I still get the same error.using MSXML2; MSXML2.XMLHTTP XMLHTTP = new XMLHTTP(); MSXML2.DOMDocument XMLDoc = new DOMDocument(); string xmlText; XmlText = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:ws='urn:microsoft-dynamics-schemas/codeunit/WS'>" + "<soapenv:Header/><soapenv:Body><ws:ShowMessage><ws:myMessage>Hello World</ws:myMessage></ws:ShowMessage></soapenv:Body></soapenv:Envelope>"; XMLHTTP.open("POST", "http://localhost:7047/DynamicsNAV/WS/CRONUS_New_Zealand_Ltd/Codeunit/MyWebService", 0, null, null); XMLHTTP.setRequestHeader("Content-type", "text/xml"); XMLHTTP.setRequestHeader("SOAPAction", "http://localhost:7047/DynamicsNAV/WS/CRONUS_New_Zealand_Ltd/Codeunit/MyWebService:ShowMessage"); XMLHTTP.send(xmlText); XMLDoc.load(XMLHTTP.responseXML); MessageBox.Show(XMLHTTP.responseText);
Error:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"><s:Body><s:Fault><faultcode xmlns:a="urn:microsoft-dynamics-schemas/error">a:Microsoft.Dynamics.Nav.Service.WebServices.ServiceBrokerException</faultcode><faultstring xml:lang="en-NZ">Parameter myMessage in method ShowMessage in service MyWebService is null! </faultstring><detail><string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">Parameter myMessage in method ShowMessage in service MyWebService is null! </string></detail></s:Fault></s:Body></s:Envelope>
OK
I have also tried to test tHe web service in visual studio using a Web References and the web service works when I do this.MyWebService.MyWebService MyWebService = new MyWebService.MyWebService(); string ReturnText; ReturnText = MyWebService.ShowMessage("Test4"); MessageBox.Show(ReturnText);
So the issue is definitly how to get the parameter passed when using SOAP. Do you know if there is another way I can call the web services from NAV?
Thanks
Claus0 -
In this post
http://blogs.msdn.com/freddyk/archive/2008/11/24/search-in-nav-2009-part-3-out-of-3.aspx
I do the same from Javascript. The code is:// Get the URL for the NAV 2009 Search Codeunit var URL = GetBaseURL() + "Codeunit/Search"; // Create XMLHTTP and send SOAP document xmlhttp = new ActiveXObject("Msxml2.XMLHTTP.4.0"); xmlhttp.open("POST", URL, false, null, null); xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); xmlhttp.setRequestHeader("SOAPAction", "DoSearch"); xmlhttp.Send('<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body><DoSearch xmlns="urn:microsoft-dynamics-schemas/codeunit/Search"><searchstring>'+searchstring+'</searchstring><result></result></DoSearch></soap:Body></soap:Envelope>'); // Find the result in the soap result and return the rsult xmldoc = xmlhttp.ResponseXML;
This runs on my machine.
The AL function looks like:
DoSearch(searchstring : Text[40];VAR result : BigText)
Good luckFreddy 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 -
Thanks Freddy
I tried your suggestion but I still get the same error. I then tried to change parameters, making the parameters var parameters and removing the return value in NAV and suddenly it worked. I had no clue why so I played a bit more and noticed all my variables were in lower case. I also noticed that the original error message referred to myMessage (first letter in lower case) despite the variable being declared as MyMessage in NAV and in the Input.xml file.
I changed my original function in NAV toShowMessage(mymessage : Text[30]) outputtext : Text[30] EXIT(mymessage);
The parameter MyMessage is changed to mymessage (all letters in lower case)
and the input.xml I changed MyMessage to mymessage (all letters in lower case again)
The web service works when I use yours suggestion for the input.xml but not when I am using my original file or arn3n suggestion.
Anyway, I guess you have to be careful when you use mix lower and upper case letter. Maybe this will be fixed in SP1.
Thanks again arn3n and Freddy for your help.
Regards
Claus0
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
- 322 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