Web Service paramater

ClausHamannClausHamann Member Posts: 80
edited 2009-05-08 in NAV Three Tier
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:
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>

Answers

  • ara3nara3n Member Posts: 9,255
    Can you paste you NAV function that you've published as webservice?

    thanks.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ClausHamannClausHamann Member Posts: 80
    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

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


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ClausHamannClausHamann Member Posts: 80
    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
  • ClausHamannClausHamann Member Posts: 80
    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

    Claus
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    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 luck
    Freddy 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.
  • ClausHamannClausHamann Member Posts: 80
    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 to
    ShowMessage(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

    Claus
Sign In or Register to comment.