XML file - Consume Web Service

scottscott Member Posts: 76
edited 2014-06-06 in Navision Attain
Hi all,

We have a client using XML to transmit their sales orders to a third party fullfillment warehouse. They developed a web service for us to use. Basically right after we create an XML file in Navsion, we have to link to the web service to consume it automatically, so their system can have orders right away. They don't want us to just send the XML file through email.

Does anyone have similar experience? What is the best way to accomplish this? They use .Net technology.

Thanks.

Scott

Comments

  • allanohlfsenallanohlfsen Member Posts: 7
    Some time in a near future perhaps the initiative at vip.navision.com will make this possible in a lean-mean way. In the meen time i think you will need to make some kind om COM wrapper for the web-client in order to be able to use it from within Navision
  • kangkang Member Posts: 1
    I think SOAP is the best way to talk to the web services. I tried SOAP automation in Navision, but couldn't make it work. If somebody has used SOAP in Navision, please let me know. Thanks.
  • Mindi@iigMindi@iig Member Posts: 6
    I hope no one minds me bringing back an old post.

    I have a client that would like to use Web Services to transmit sales orders and other information from another package to avoid using Biz Talk Server.

    Does anyone know if this is possible? And if it is, it is a good idea or not?

    I'm having a difficult time finding the information I need to determine this.

    Thanks,

    Mindi
  • PrebenRasmussenPrebenRasmussen Member Posts: 137
    I have successfully communicated with a web-service from within Navision.

    I can't give it for free, as a lot of hours where put into it. Let me find it from my toolbox and get back to you regarding the terms - that is, if you are interested.

    It has been developed using Microsoft.NET. So the framework is required to be installed on the clients using it.
  • PrebenRasmussenPrebenRasmussen Member Posts: 137
    I have now looked into my solution. It seems it may be more than you expect/need.

    The webservice, that I communicate with delivevers both a stream of bytes containing an xml-response and a binary stream containing a bitmap.

    So two responses are actually handled in my solution. This is not normal, I think!

    It has been programmed as an automation server available in Navision as an Automation type variable. As the Navision programmer this is the interface you can use:

    One property:
    ServiceLocation := "http://1.2.3.4/Location/Service.asmx";
    One method:
    OK := SendRequest(XmlFileName, BinaryFileName);

    So the property sets the location of the webservice, while the method tells the automation server where to store the xml and binary files for later use by Navision. Actually XmlFileName is also used for outgoing information to the webservice, the file is read by the automation server and send to the webservice as a parameter.

    That's it!
  • hylafaxhylafax Member Posts: 1
    Here you are..

    The easiest way to achive this is to use SOAP (in may humble opinion).
    Below you will find whole codeunit, however - as I suppose -
    you will also need Microsoft SOAP Toolkit 3.0. You can download it from
    Microsoft website - I'm sure you'll find it.

    ...and below below there is also some specification stuff for this example to work.
    have fun!

    ******************************************************
    OBJECT Codeunit 50030 WebService
    {
    OBJECT-PROPERTIES
    {
    Data=04-12-09;
    Godzina=[ 1:43:37];
    Zmodyfikowany=Tak;
    Lista wersji=;
    }
    PROPERTIES
    {
    OnRun=BEGIN
    CallWebService;
    END;

    }
    CODE
    {
    VAR
    DOMNode@1101417012 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF80-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMNode";
    SoapHttpConn@1101417000 : Automation "{91147A58-DFE4-47C0-8E76-987FC1A6001B} 3.0:{0AF40C53-9257-11D5-87EA-00B0D0BE6479}:'Microsoft Soap Type Library v3.0'.HttpConnector30";
    SoapSerialize@1101417001 : Automation "{91147A58-DFE4-47C0-8E76-987FC1A6001B} 3.0:{B76585B0-9257-11D5-87EA-00B0D0BE6479}:'Microsoft Soap Type Library v3.0'.SoapSerializer30";
    XMLDom@1101417002 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{F5078F32-C551-11D3-89B9-0000F81FE221}:'Microsoft XML, v4.0'.DOMDocument30";
    DOMElement@1101417003 : Automation "{F5078F18-C551-11D3-89B9-0000F81FE221} 4.0:{2933BF86-7B36-11D2-B20E-00C04F983E60}:'Microsoft XML, v4.0'.IXMLDOMElement";

    PROCEDURE CallWebService@1101417001();
    BEGIN
    IF ISCLEAR(SoapHttpConn) THEN
    CREATE(SoapHttpConn);
    SoapHttpConn.Property('EndPointURL','http://localhost:8080/NewFile.asmx');
    SoapHttpConn.Connect;
    SoapHttpConn.Property('SoapAction','http://tempuri.org/Add');
    SoapHttpConn.BeginMessage;
    IF ISCLEAR(SoapSerialize) THEN
    CREATE(SoapSerialize);
    SoapSerialize.Init(SoapHttpConn.InputStream);
    SoapSerialize.StartEnvelope('','STANDARD');
    SoapSerialize.StartBody;
    SoapSerialize.WriteXml('<Add xmlns="http://tempuri.org/"><a>2</a><b>3</b></Add>');
    SoapSerialize.EndBody;
    SoapSerialize.EndEnvelope;
    SoapHttpConn.EndMessage;

    IF ISCLEAR(XMLDom) THEN
    CREATE(XMLDom);
    XMLDom.async := FALSE;
    XMLDom.load(SoapHttpConn.OutputStream);
    DOMElement := XMLDom.documentElement;
    DOMNode := DOMElement.selectSingleNode('.//AddResult');
    MESSAGE(DOMNode.text);
    END;

    EVENT XMLDom@1101417002::ondataavailable@198();
    BEGIN
    END;

    EVENT XMLDom@1101417002::onreadystatechange@-609();
    BEGIN
    END;

    BEGIN
    {
    Microsoft SOAP Toolkit 3.0

    Wojciech Lukowski
    MBS Navision Junior Consultant
    wojciech.lukowski@NOSPAM.it.integro.pl
    IT.integro POLAND, MBS Partner
    }
    END.
    }
    }
    ********************************************************

    Below below part:
    example GENERATES:

    <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
    - <SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/&quot; xmlns:SOAPSDK1="http://www.w3.org/2001/XMLSchema&quot; xmlns:SOAPSDK2="http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:SOAPSDK3="http://schemas.xmlsoap.org/soap/encoding/&quot; xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    - <SOAP-ENV:Body>
    - <Add xmlns="http://tempuri.org/"&gt;
    <a>2</a>
    <b>3</b>
    </Add>
    </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

    example RECEIVES:

    <?xml version="1.0" encoding="utf-8" ?>
    - <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/&quot; xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    - <soap:Body>
    - <AddResponse xmlns="http://tempuri.org/"&gt;
    <AddResult>5</AddResult>
    </AddResponse>
    </soap:Body>
    </soap:Envelope>


    WEBSERVICE FORMAT
    REQUEST

    POST /NewFile.asmx HTTP/1.1
    Host: localhost
    Content-Type: text/xml; charset=utf-8
    Content-Length: length
    SOAPAction: "http://tempuri.org/Add&quot;

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd="http://www.w3.org/2001/XMLSchema&quot; xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    <soap:Body>
    <Add xmlns="http://tempuri.org/"&gt;
    <a>int</a>
    <b>int</b>
    </Add>
    </soap:Body>
    </soap:Envelope>

    and RESPONSE

    HTTP/1.1 200 OK
    Content-Type: text/xml; charset=utf-8
    Content-Length: length

    <?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&quot; xmlns:xsd="http://www.w3.org/2001/XMLSchema&quot; xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    <soap:Body>
    <AddResponse xmlns="http://tempuri.org/"&gt;
    <AddResult>int</AddResult>
    </AddResponse>
    </soap:Body>
    </soap:Envelope>

    WEBSERVICE IMPLEMENTATION - just an example - what you do inside it's your own business :)

    <%@ WebService language="VB" class="classTest" %>

    Imports System
    Imports System.Web.Services
    Imports System.Xml.Serialization

    Public Class classTest

    <WebMethod> Public Function Add(a As Integer, b As Integer) As Integer
    Return a + b
    End Function

    End Class

    regards,
    Wojciech Lukowski
    MBS Consultant
  • rwabelrwabel Member Posts: 32
    I'm also interested in sending a file (text file) from navision to a webserver.
    Since Navision 4.0 is now using the .NET framework, I guess SOAP solution is obsolete. Is there now another and even better a simpler way to achieve that?

    thanks
  • dilipkinthadadilipkinthada Member Posts: 11
    Hi hylafax,

    I have tried your code for connecting to third party web service and retreiving data from xml file
    It worked for me...
    Thanks a lot

    Regards
    Dilip.
  • MBrodie1979MBrodie1979 Member Posts: 21
    Thank you for the code example. I imported your codeunit into NAV but when I try run it i get this error:

    Call to member endmessage failed. Connector returned the following error message:

    Connector:Connection failed or server refused connection (request might exceed MaxPostSize).

    Any ideas? :-k
  • Cem_KaraerCem_Karaer Member Posts: 281
    hylafax, you are great!

    It was the clearest and simplest solution I have ever met. Thank you for your share!

    @admin: I suggest that thread to be transferred to "tips and tricks" section.

    Regards
    Cem Karaer @ Pargesoft
    Dynamics NAV Developer since 2005
Sign In or Register to comment.