[NAV2009 R2] - WebService communication from NAV to NAV

toLLtotoLLto Member Posts: 34
edited 2015-05-15 in NAV Three Tier
Hi,

I need a WebService communication between two NAV 2009 databases (from NAV_Src to NAV_Dest).

On NAV_Dest I published a Codeunit with a function "CreateUpdateGLAccount" which should create or update a GL Account from given parameters and return some simple status text. I need to call this webservice from another database NAV_Src. Here is my code on NAV_Src:
  IF ISCLEAR(XmlHttp) THEN
    CREATE(XmlHttp, TRUE,TRUE);
  IF ISCLEAR(XmlDoc) THEN
    CREATE(XmlDoc);
  XmlDoc.async(FALSE);

  // call webservice CreateUpdateGLAccount
  url := 'http://server:7047/NAV_Dest/WS/companyName/Codeunit/IntegrationService';
  XmlHttp.open('POST', url, FALSE);
  XmlHttp.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
  soap :=
      '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" '+
      ' xmlns:nav="urn:microsoft-dynamics-schemas/codeunit/IntegrationService"> '+
          '<soapenv:Body> '+
              '<nav:CreateUpdateGLAccount> '+                 
                  '<nav:no>'+GLAccount."No."+'</nav:no> '+
                  '<nav:name>'+GLAccount.Name+'</nav:name> '+
              '</nav:CreateUpdateGLAccount> '+
          '</soapenv:Body> '+
      '</soapenv:Envelope>';
    XmlHttp.send(soap);
    IF XmlHttp.status <> 200 THEN
      ERROR('Http error '
            + FORMAT(XmlHttp.status)+': '+XmlHttp.statusText + ' ' +XmlHttp.responseText);
    XmlDoc.load(XmlHttp.responseXML);
    MESSAGE(_url+'\\'+_soap+'\\'+XmlHttp.statusText+'\\'+XmlDoc.text);

NAV_Dest
CreateUpdateGLAccount(No : Code[20];Name : Text[30])
GLAccount.RESET;
GLAccount.INIT;
GLAccount.VALIDATE("No.", No);
GLAccount.VALIDATE(Name, Name);

IF NOT _GLAccount.INSERT(TRUE) THEN BEGIN
  GLAccount.MODIFY(TRUE);
  EXIT('updated');
END ELSE
  EXIT('inserted');

I get no error and a correct status 200 but it looks like the CreateUpdateGLAccount function on NAV_Src is not called (does nothing). When I call CreateUpdateGLAccount on NAV_Dest from a simple C# application everything works fine. I tested it with Fiddler - both requests from NAV and from C# are genereting same Soap Envelope. For the C# request I get a correct response with message "update"/"inserted", but for the request from NAV_Src the response in Fiddler contains just the the wsdl xml metadata

What am I missing? Is this something related to authentication? Both databases run on same server and are in the same domain.

I tried to add SOAPAction to the request Header
XmlHttp.setRequestHeader('SOAPAction', 'CreateUpdateGLAccount2');
but then I get an error "SOAP message is invalid!'.

Comments

  • MarijnMarijn Member Posts: 69
    As far as I know, you'll need to pass a username and password along. Try adding them as a fourth and fifth parameter:
    xmlhttp.open('POST', url, FALSE, USERNAME, PASSWORD);
  • toLLtotoLLto Member Posts: 34
    Marijn wrote:
    As far as I know, you'll need to pass a username and password along. Try adding them as a fourth and fifth parameter:
    xmlhttp.open('POST', url, FALSE, USERNAME, PASSWORD);

    no luck, still same problem.

    It's really strange, I can call any external Webservice from NAV, I can call my NAV webservice from C#, but I'm not able get it work when I try to call a NAV Webservice from different NAV Instance.
  • MarijnMarijn Member Posts: 69
    And what about NAV to NAV using a single instance? For example, calling a webservice from company A to company B?
  • vaprogvaprog Member Posts: 1,140
    Are you sending your request to the right url. And, are you POSTing your request? If you get back the WSDL you're probably not using the service url and likely using http GET rather than POST.
Sign In or Register to comment.