Web Service - Parameter in method is null

Troubles_In_ParadiseTroubles_In_Paradise Member Posts: 588
edited 2011-12-12 in NAV Three Tier
Hi guys, I ask your help for a problem with Web Service (this is the first time I use Web Service :oops:).
1. I created a simple CU that receives, as a parameter, the customer code and returns the Entry No. of the last Customer Ledger Entry for this customer.
2. I exposed it as WS (following is the code of this CU):
ExitLastCustomer(parametro : Text[30]) : Integer
CLEAR(Customer);
Customer.RESET;
Customer.SETRANGE("Customer No.",parametro);
Customer.FINDLAST;
EXIT(Customer."Entry No.");
3. I created a CU that should consume this WS
IF ISCLEAR(XMLDoc) THEN
  CREATE(XMLDoc);

XMLDoc.async := FALSE;
XMLDoc.load('C:\Input2.xml');

IF ISCLEAR(XMLHttp) THEN
  CREATE(XMLHttp);

XMLHttp.open('POST','http://localhost:7047/DynamicsNAV/WS/Riktest/Codeunit/ExitLastCustomerWSName',0);
XMLHttp.setRequestHeader('Content-type','text/xml');
XMLHttp.setRequestHeader('SOAPAction','ExitLastCustomer');

XMLHttp.send(XMLDoc);

XMLDoc.load(XMLHttp.responseXML);
XMLDoc.save('C:\temp.xml');

XMLDoc.load(XMLHttp.responseBody);
XMLNode := XMLDoc.selectSingleNode('//Soap:Envelope/Soap:Body/ExitLastCustomer_Result/return_value/');
MESSAGE(XMLNode.text);
this is the Input2.xml file
<?xml version="1.0" encoding="UTF-8"?>
  <soap:Envelope xmlns:nav="urn:microsoft-dynamics-schemas/codeunit/NAVWebServices" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Header/> 
      <soap:Body> 
        <nav:ExitLastCustomer> 
          <nav:parametro>10000</nav:parametro> 
        </nav:ExitLastCustomer> 
    </soap:Body> 
  </soap:Envelope>
to do what I did I followed this links:
http://mibuso.com/blogs/ara3n/2009/01/2 ... companies/ and
viewtopic.php?t=39037
but the error is always the same: parametro is null...
has anyone got an idea?
Thx in advance!
~Rik~
It works as expected... More or Less...

Answers

  • nileshshelarnileshshelar Member Posts: 13
    Hi Rik,

    You create below method in your codeunit (as web service).
    ExitLastCustomer(parametro : Text[30]) : Integer

    When you are using this web service you must pass the parameters for the method.

    e.g. C# .net code
    Testcodeunit Service_Testcodeunit = new Testcodeunit();
    Service_Testcodeunit.UseDefaultCredentials = true;
    Service_Testcodeunit.Url = sNAV_DT_RDNPath.Trim() + "/Codeunit/Testcodeunit";
    Service_Testcodeunit.ExitLastCustomer('100000000');
  • Troubles_In_ParadiseTroubles_In_Paradise Member Posts: 588
    <?xml version="1.0" encoding="UTF-8"?>
      <soap:Envelope xmlns:nav="urn:microsoft-dynamics-schemas/codeunit/NAVWebServices" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
        <soap:Header/> 
          <soap:Body> 
            <nav:ExitLastCustomer> 
              <nav:parametro>10000</nav:parametro> 
            </nav:ExitLastCustomer> 
        </soap:Body> 
      </soap:Envelope>
    
    Thx for replay.
    If you read the previous peace of code you can see that I try to pass a value to parametro...
    ~Rik~
    It works as expected... More or Less...
  • Troubles_In_ParadiseTroubles_In_Paradise Member Posts: 588
    Solved, modifing the Input2.xml file as follow
    <?xml version="1.0" encoding="UTF-8"?>
    <soap:Envelope xmlns:nav="urn:microsoft-dynamics-schemas/codeunit/ExitLastCustomerWSName"' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
      <soap:Body>
        <nav:ExitLastCustomer>
          <nav:parametro>919</nav:parametro>
        </nav:ExitLastCustomer> 
      </soap:Body>
    </soap:Envelope>
    
    ~Rik~
    It works as expected... More or Less...
Sign In or Register to comment.