Invoking webservice from Navision

shettarvikasshettarvikas Member Posts: 106
Hi All,

Can we invoke Web Service from Navision directly.

Scenario:
From Navision, we need to send some data to third party application through web service. In this regard, Can Navision call the web service of 3rd party application directly.

Request for help in this regard.

Thanks & regards,
Vikas

Comments

  • rvduurenrvduuren Member Posts: 92
    Hello Vikas,

    Yes we can :)
    Here is an out of the box working example (call a webservice for validating a VAT No.)..

    Dependencies: MS SOAP Toolkit 3.0.

    WSDL: http://ec.europa.eu/taxation_customs/vi ... tPort?wsdl
    OBJECT Codeunit 99901 VAT Check
    {
      OBJECT-PROPERTIES
      {
        Date=23-01-08;
        Time=13:27:36;
        Modified=Yes;
        Version List=SML;
      }
      PROPERTIES
      {
        OnRun=BEGIN
                IF ISCLEAR(Connector) THEN
                  CREATE(Connector);
    
                //Connector.Property('ProxyServer','isaserver');
                //Connector.Property('ProxyPassword','proxypass');
                //Connector.Property('ProxyUser','username');
    
                Connector.Property('EndPointURL','http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl');
                Connector.Connect;
                Connector.Property('SoapAction','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
                Connector.BeginMessage;
    
                CREATE(Serializer);
                Serializer.Init(Connector.InputStream);
    
                Serializer.StartEnvelope('','STANDARD','utf-16');
                Serializer.StartBody('STANDARD');
                Serializer.StartElement('checkVat','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
    
                  Serializer.StartElement('countryCode','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
                  Serializer.WriteString('GB');
                  Serializer.EndElement;
                  Serializer.StartElement('vatNumber','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
                  Serializer.WriteString('704767477');
                  Serializer.EndElement;
    
                Serializer.EndElement;
                Serializer.EndBody;
                Serializer.EndEnvelope;
    
                Connector.EndMessage;
    
                IF ISCLEAR(XMLDOM) THEN
                  CREATE(XMLDOM);
                XMLDOM.load(Connector.OutputStream);
                XMLNode := XMLDOM.selectSingleNode('//valid');
                IF NOT ISCLEAR(XMLNode) THEN
                  MESSAGE(XMLNode.text);
                XMLDOM.save('c:\vat.xml');
                CLEAR(XMLDOM);
                CLEAR(Connector);
              END;
    
      }
      CODE
      {
        VAR
          Serializer@1000000000 : Automation "{91147A58-DFE4-47C0-8E76-987FC1A6001B} 3.0:{B76585B0-9257-11D5-87EA-00B0D0BE6479}:'Microsoft Soap Type Library v3.0'.SoapSerializer30";
          Connector@1000000004 : Automation "{91147A58-DFE4-47C0-8E76-987FC1A6001B} 3.0:{0AF40C53-9257-11D5-87EA-00B0D0BE6479}:'Microsoft Soap Type Library v3.0'.HttpConnector30";
          XMLDOM@1000000001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v6.0'.DOMDocument";
          XMLNode@1000000003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";
    
        EVENT XMLDOM@1000000001::ondataavailable@198();
        BEGIN
        END;
    
        EVENT XMLDOM@1000000001::onreadystatechange@-609();
        BEGIN
        END;
    
        BEGIN
        END.
      }
    }
    
    Met vriendelijke groet, best regards,

    Rvduuren
  • bostjanlbostjanl Member Posts: 107
    Great example. It solved my problem. Any chance to get .NET example?
  • rvduurenrvduuren Member Posts: 92
    bostjanl wrote:
    Great example. It solved my problem. Any chance to get .NET example?
    Hello,
    Sure, Navision 4 ReportingServices 2005 is based on webservices
    Met vriendelijke groet, best regards,

    Rvduuren
  • MagnoMagno Member Posts: 168
    Hi,

    I installed SOAP Toolkit v3.0, but when the create on the connector is invoked, i get this one:
    ---------------------------
    Microsoft Business Solutions-Navision
    ---------------------------
    This message is for C/AL programmers:
    
    Could not create an instance of the OLE control or Automation server identified by
    GUID={91147A58-DFE4-47C0-8E76-987FC1A6001B} 3.0:{0AF40C52-9257-11D5-87EA-00B0D0BE6479}:'Microsoft Soap Type Library v3.0'.SoapConnector30.
    Check that the OLE control or Automation server is correctly installed and registered.
    
    ---------------------------
    OK   
    ---------------------------
    

    Any ideas ?

    This is the code i am using:
          if ISCLEAR(locautSoapHttpConnector) then
            CREATE(locautSoapHttpConnector);
          locautSoapHttpConnector.Property('EndPointURL', 'http://srv056/Holidays/Services.asmx');
          locautSoapHttpConnector.Connect;
          //locautSoapHttpConnector.Property('AuthUser', 'User');
          //locautSoapHttpConnector.Property('AuthPassword', 'Password');
          locautSoapHttpConnector.Property('Timeout', 5 * 1000);
          locautSoapHttpConnector.Property('SoapAction','http://Holidays/Services/GetDayInfo');
          locautSoapHttpConnector.BeginMessage;
    
    There are no bugs, only random undocumented features...
    ---
    My Blog: http://NAV-Magno.be
  • MalajloMalajlo Member Posts: 294
    Try with 'Microsoft XML, v3.0'.ServerXMLHTTP

    SOAP uses XML.
    Name	DataType	Subtype	Length
    XMLDocOut	Automation	'Microsoft XML, v3.0'.DOMDocument	
    XMLEnv	Automation	'Microsoft XML, v3.0'.IXMLDOMNode	
    XMLBody	Automation	'Microsoft XML, v3.0'.IXMLDOMNode	
    XMLAct	Automation	'Microsoft XML, v3.0'.IXMLDOMNode	
    XMLPar	Automation	'Microsoft XML, v3.0'.IXMLDOMNode	
    ADOStream	Automation	'Microsoft ActiveX Data Objects 2.8 Library'.Stream	
    XMLDomElement	Automation	'Microsoft XML, v3.0'.IXMLDOMElement	
    XMLHTTP	Automation	'Microsoft XML, v3.0'.ServerXMLHTTP	
    
    SOAP(URL : Text[150];Action : Text[30];TicketProviderID : Code[20];EventID : Code[20];EventProvider : Record "Event Ticket Provider") :
    ....
    CLEAR(XMLDocOut); 
    CLEAR(XMLEnv) ;
    CLEAR(XMLBody) ;
    CLEAR(XMLAct) ;
    CLEAR(XMLPar) ;
    CLEAR(ADOStream) ;
    CREATE(ADOStream) ;
    ADOStream.Type := 1 ;
    ADOStream.Open ;
    CREATE(XMLDocOut); 
    XMLDOMManagement.SetNormalCase;
    
    XMLProccesingInst := XMLDocOut.createProcessingInstruction('xml','version=''1.0'' encoding=''utf-8''');
    XMLDocOut.appendChild(XMLProccesingInst); 
    
    XMLEnv := XMLDocOut.createElement('soap:Envelope') ;
    XMLDocOut.appendChild(XMLEnv);
    XMLDOMManagement.AddAttribute(XMLEnv,'xmlns:soap','http://schemas.xmlsoap.org/soap/envelope/') ;
    XMLDOMManagement.AddAttribute(XMLEnv,'xmlns:xsi','http://www.w3.org/2001/XMLSchema-instance') ;
    XMLDOMManagement.AddAttribute(XMLEnv,'xmlns:xsd','http://www.w3.org/2001/XMLSchema') ;
    
    XMLDomElement := XMLDocOut.documentElement ;
    XMLBody := XMLDocOut.createElement('soap:Body') ;
    XMLDomElement.appendChild(XMLBody) ;
    
    XMLAct :=  XMLDocOut.createElement(Action) ;
    XMLBody.appendChild(XMLAct) ;
    
    XMLPar := XMLDocOut.createNode(1,'language','') ;
    XMLPar.text := TicketProviders.Language ;
    XMLAct.appendChild(XMLPar) ;
    
    XMLPar := XMLDocOut.createNode(1,'userName','') ;
    XMLPar.text := TicketProviders."User Name" ;
    XMLAct.appendChild(XMLPar) ;
    
    XMLPar := XMLDocOut.createNode(1,'passWord','') ;
    XMLPar.text := TicketProviders.Password ;
    XMLAct.appendChild(XMLPar) ;
    SendSOAP(URL,URItemp+Action) ;
    
    
    SendSOAP(SOAPURL : Text[150];SOAPAction : Text[150])
    CREATE(XMLHTTP) ;
    XMLHTTP.open('POST',SOAPURL,FALSE) ;
    XMLHTTP.setRequestHeader('Content-Type', 'text/xml; charset=utf-8') ;
    ...
    
  • ta5ta5 Member Posts: 1,164
    I would prefer xmlhttp instead of soap toolkit, because soap toolkit reached end of life and soap toolkit has to be registered on each workstation, whereas xmlhttp is part of the msxml6.dll and part of almost every current windows installation:

    Here's a very helpful example showing both ways.
    http://www.mibuso.com/dlinfo.asp?FileID=539


    Hope this helps
    Thomas
  • MagnoMagno Member Posts: 168
    This is complete different from the code above then?

    It seemed to have worked for others.
    There are no bugs, only random undocumented features...
    ---
    My Blog: http://NAV-Magno.be
  • ta5ta5 Member Posts: 1,164
    I have worked quite a lot with webservices and using code as used in the provided link worked best. Some time ago I have also used soap toolkit, but it is now end of life now. Of course, soap toolkit still works.
  • pedgaardpedgaard Member Posts: 24
    rvduuren wrote:
    Hello Vikas,

    Yes we can :)
    Here is an out of the box working example (call a webservice for validating a VAT No.)..

    Dependencies: MS SOAP Toolkit 3.0.

    WSDL: http://ec.europa.eu/taxation_customs/vi ... tPort?wsdl
    OBJECT Codeunit 99901 VAT Check
    {
      OBJECT-PROPERTIES
      {
        Date=23-01-08;
        Time=13:27:36;
        Modified=Yes;
        Version List=SML;
      }
      PROPERTIES
      {
        OnRun=BEGIN
                IF ISCLEAR(Connector) THEN
                  CREATE(Connector);
    
                //Connector.Property('ProxyServer','isaserver');
                //Connector.Property('ProxyPassword','proxypass');
                //Connector.Property('ProxyUser','username');
    
                Connector.Property('EndPointURL','http://ec.europa.eu/taxation_customs/vies/api/checkVatPort?wsdl');
                Connector.Connect;
                Connector.Property('SoapAction','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
                Connector.BeginMessage;
    
                CREATE(Serializer);
                Serializer.Init(Connector.InputStream);
    
                Serializer.StartEnvelope('','STANDARD','utf-16');
                Serializer.StartBody('STANDARD');
                Serializer.StartElement('checkVat','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
    
                  Serializer.StartElement('countryCode','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
                  Serializer.WriteString('GB');
                  Serializer.EndElement;
                  Serializer.StartElement('vatNumber','urn:ec.europa.eu:taxud:vies:services:checkVat:types');
                  Serializer.WriteString('704767477');
                  Serializer.EndElement;
    
                Serializer.EndElement;
                Serializer.EndBody;
                Serializer.EndEnvelope;
    
                Connector.EndMessage;
    
                IF ISCLEAR(XMLDOM) THEN
                  CREATE(XMLDOM);
                XMLDOM.load(Connector.OutputStream);
                XMLNode := XMLDOM.selectSingleNode('//valid');
                IF NOT ISCLEAR(XMLNode) THEN
                  MESSAGE(XMLNode.text);
                XMLDOM.save('c:\vat.xml');
                CLEAR(XMLDOM);
                CLEAR(Connector);
              END;
    
      }
      CODE
      {
        VAR
          Serializer@1000000000 : Automation "{91147A58-DFE4-47C0-8E76-987FC1A6001B} 3.0:{B76585B0-9257-11D5-87EA-00B0D0BE6479}:'Microsoft Soap Type Library v3.0'.SoapSerializer30";
          Connector@1000000004 : Automation "{91147A58-DFE4-47C0-8E76-987FC1A6001B} 3.0:{0AF40C53-9257-11D5-87EA-00B0D0BE6479}:'Microsoft Soap Type Library v3.0'.HttpConnector30";
          XMLDOM@1000000001 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{F6D90F11-9C73-11D3-B32E-00C04F990BB4}:'Microsoft XML, v6.0'.DOMDocument";
          XMLNode@1000000003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 6.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v6.0'.IXMLDOMNode";
    
        EVENT XMLDOM@1000000001::ondataavailable@198();
        BEGIN
        END;
    
        EVENT XMLDOM@1000000001::onreadystatechange@-609();
        BEGIN
        END;
    
        BEGIN
        END.
      }
    }
    

    Hi there rvduuren,

    I am trying to learn by example, but in this case the WDSL has changed address. I thought I could just use your code, and substitute the new address, but it didn't work. Do you have some suggestions on what else needs to be fixed for Navision to communicate with it?

    The new address is now: http://ec.europa.eu/taxation_customs/vi ... rvice.wsdl
    Seems same parameters in my eyes, countrycode and vatnumber.

    I have used the same webservice in a VB.NET + VBA Excel Solution, but Navision does not give me the toolbox to automatically setup the connection :)

    Cheers,
    pedgaard
Sign In or Register to comment.