{"id":92,"date":"2014-02-06T12:12:33","date_gmt":"2014-02-06T19:12:33","guid":{"rendered":"https:\/\/syncimprov.com\/?p=92"},"modified":"2014-02-06T12:12:33","modified_gmt":"2014-02-06T19:12:33","slug":"calling-a-lynx-business-process-through-the-web-service","status":"publish","type":"post","link":"https:\/\/syncimprov.com\/?p=92","title":{"rendered":"Calling a LynX Business Process (through the web service)"},"content":{"rendered":"<p>In this post, I&#8217;ll describe how to call a (LynX) business process through the web service.<br \/>\nNote: This post assumes that you are calling the web service from .Net. The web service can be called by any external app that can consume web services.<\/p>\n<h2>Web Service Methods<\/h2>\n<p>LynX Web Service provides a handful of methods\/operations to submit and retrieve documents (if you are wondering why you can use the same web method for different E1 functions, read my previous posts). The web service is a SOAP based web service (we are working on a REST based implementation). Here is a partial screenshot of the operations provided by the service.<\/p>\n<p><a href=\"https:\/\/syncimprov.com\/wp-content\/uploads\/2014\/02\/web-service-methods.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/syncimprov.com\/wp-content\/uploads\/2014\/02\/web-service-methods.png\" alt=\"Web Service Methods\" width=\"465\" height=\"378\" class=\"aligncenter size-full wp-image-95\" srcset=\"https:\/\/syncimprov.com\/wp-content\/uploads\/2014\/02\/web-service-methods.png 465w, https:\/\/syncimprov.com\/wp-content\/uploads\/2014\/02\/web-service-methods-300x244.png 300w\" sizes=\"auto, (max-width: 465px) 100vw, 465px\" \/><\/a><\/p>\n<p>To call a business process, you need to call one of the Process Document methods. In its simplest form, the Process Document method requires three parameters:<\/p>\n<ol>\n<li>document: the string representation of the XML document. The document must be in Unicode (utf-16) format.<\/li>\n<li>password: the E1 password of the user specified in the e1user attribute of the document.<\/li>\n<li>attachmentSetID: the id of the attachment set (if attachments were submitted using the CreateAttachmentSet and AddAttachmentToSet methods)<\/li>\n<\/ol>\n<h2>Creating the input document<\/h2>\n<p>You can create the input document using any of the XML creation methods (XmlDocument, XmlWriter etc.). However, there is an easier way to do it: use the XML Schema to create a typed class and serialize the object to create the XML document. You can use xsd.exe to create the typed class. I prefer to use a tool called Xsd2Code to create typed classes as it is integrated with the Visual Studio IDE. You can download it <a href=\"http:\/\/xsd2code.codeplex.com\/\" title=\"Xsd2Code\" target=\"_blank\" rel=\"noopener\">here<\/a>. <\/p>\n<p>Side notes on Xsd2Code (see screenshots below):<\/p>\n<ul>\n<li>Make sure that you set the target framework to your framework level and the GenerateXmlAttributes property to True<\/li>\n<li>You can auto-generate the code by setting the Custom Tool property of the schema file to Xsd2CodeCustomTool<\/li>\n<\/ul>\n<p><a href=\"https:\/\/syncimprov.com\/wp-content\/uploads\/2014\/02\/xsd2code1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/syncimprov.com\/wp-content\/uploads\/2014\/02\/xsd2code1.png\" alt=\"Xsd2Code1\" width=\"589\" height=\"659\" class=\"aligncenter size-full wp-image-107\" srcset=\"https:\/\/syncimprov.com\/wp-content\/uploads\/2014\/02\/xsd2code1.png 589w, https:\/\/syncimprov.com\/wp-content\/uploads\/2014\/02\/xsd2code1-268x300.png 268w\" sizes=\"auto, (max-width: 589px) 100vw, 589px\" \/><\/a><\/p>\n<p><a href=\"https:\/\/syncimprov.com\/wp-content\/uploads\/2014\/02\/xsd2code2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/syncimprov.com\/wp-content\/uploads\/2014\/02\/xsd2code2.png\" alt=\"Xsd2Code2\" width=\"331\" height=\"154\" class=\"aligncenter size-full wp-image-108\" srcset=\"https:\/\/syncimprov.com\/wp-content\/uploads\/2014\/02\/xsd2code2.png 331w, https:\/\/syncimprov.com\/wp-content\/uploads\/2014\/02\/xsd2code2-300x140.png 300w\" sizes=\"auto, (max-width: 331px) 100vw, 331px\" \/><\/a><\/p>\n<p>Here\u2019s a function to create a typed object for the business process ERP.EOne.Training1 (download the solution at the end of this post).<\/p>\n<p>[code language=&#8221;csharp&#8221;]<\/p>\n<p>    static string CreateDocument()<br \/>\n    {<br \/>\n      \/\/ create the document using the typed class<br \/>\n      BusinessDocument bd = new BusinessDocument();<br \/>\n      bd.processsettings = new ProcessSettings();<br \/>\n      \/\/ this tells lynX which business process to execute<br \/>\n      bd.processsettings.aelliusrequestid = &quot;ERP.EOne.Training1&quot;;<br \/>\n      bd.processsettings.anonymous = false;<br \/>\n      bd.processsettings.debug = false;<br \/>\n      bd.processsettings.e1role = &quot;*ALL&quot;;<br \/>\n      bd.processsettings.e1user = &quot;E1USER&quot;;<br \/>\n      bd.processsettings.environment = &quot;JDV910&quot;;<br \/>\n      bd.processsettings.keeprepository = true;<br \/>\n      bd.processsettings.lynxapp = &quot;LynX App&quot;;<br \/>\n      bd.processsettings.lynxuser = &quot;E1USER&quot;;<\/p>\n<p>      bd.document = new Document();<br \/>\n      bd.document.input = new Input();<br \/>\n      bd.document.input.AddressName = &quot;*Test*&quot;;<\/p>\n<p>      \/\/ serialize the XML<br \/>\n      XmlSerializer xs = new XmlSerializer(bd.GetType());<br \/>\n      StringBuilder sb = new StringBuilder();<br \/>\n      XmlWriterSettings xws = new XmlWriterSettings() { Indent = true, Encoding = System.Text.Encoding.Unicode };<br \/>\n      using (XmlWriter xw = XmlWriter.Create(sb, xws))<br \/>\n      {<br \/>\n        xs.Serialize(xw, bd);<br \/>\n      }<\/p>\n<p>      \/\/ this is XML document that needs to be submitted<br \/>\n      string document = sb.ToString();<\/p>\n<p>      return document;<br \/>\n    }<br \/>\n[\/code]<\/p>\n<p>This function creates an XML document that looks like this:<\/p>\n<p>[code language=&#8221;xml&#8221;]<br \/>\n&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-16&quot;?&gt;<br \/>\n&lt;aelliusconnector&gt;<br \/>\n  &lt;processsettings<br \/>\n    aelliusrequestid=&quot;ERP.EOne.Training1&quot;<br \/>\n    environment=&quot;JDV910&quot;<br \/>\n    debug=&quot;false&quot;<br \/>\n    processmode=&quot;object&quot;<br \/>\n    anonymous=&quot;false&quot;<br \/>\n    e1user=&quot;E1USER&quot;<br \/>\n    e1role=&quot;*ALL&quot;<br \/>\n    lynxapp=&quot;LynX App&quot;<br \/>\n    lynxuser=&quot;E1USER&quot; \/&gt;<br \/>\n  &lt;document&gt;<br \/>\n    &lt;input&gt;<br \/>\n      &lt;AddressName&gt;*Test*&lt;\/AddressName&gt;<br \/>\n    &lt;\/input&gt;<br \/>\n    &lt;output \/&gt;<br \/>\n  &lt;\/document&gt;<br \/>\n&lt;\/aelliusconnector&gt;<br \/>\n[\/code]<\/p>\n<h2>Submitting the document<\/h2>\n<p>To call the web service, you can simply add a service reference or just reference LynXProxy, a class library that is part of the product.<br \/>\nHere is a function to submit the document to the web service:<\/p>\n<p>[code language=&#8221;csharp&#8221;]<br \/>\n    static void SubmitDocument(string document)<br \/>\n    {<br \/>\n      WebProxy wb = new WebProxy();<\/p>\n<p>      \/\/ set the url for the web service<br \/>\n      wb.SetUrl(&quot;http:\/\/yourwebserice.com\/lynxweservice\/lynxwebservie.asmx&quot;);<\/p>\n<p>      \/\/ set the credentials to access the web serivce<br \/>\n      \/\/ the web sevice supports windows integrated and<br \/>\n      \/\/ basic authentication. these are not necessarily the<br \/>\n      \/\/ crendentails to access E1.<br \/>\n      \/\/ named parameters used for clarity<br \/>\n      wb.SetCredentials(userName: &quot;userid&quot;, password: &quot;password&quot;, domain: &quot;domain&quot;);<\/p>\n<p>      \/\/ login to E1 through the web service<br \/>\n      \/\/ this is optional<br \/>\n      wb.LoginUser(userID: &quot;E1USER&quot;,<br \/>\n        password: &quot;e1password&quot;,<br \/>\n        role: &quot;*ALL&quot;, environment: &quot;JDV910&quot;,<br \/>\n        debug: false);<\/p>\n<p>      \/\/ submit the document<br \/>\n      string output = wb.ProcessDocument(document: document, password: &quot;e1password&quot;, attachmentsetID: 0);<\/p>\n<p>      \/\/ load the XML document &#8211; you can also deserialize it<br \/>\n      \/\/ to a typed object<br \/>\n      XmlDocument xml = new XmlDocument();<br \/>\n      xml.PreserveWhitespace = true;<br \/>\n      xml.LoadXml(output);<\/p>\n<p>      \/\/ check the status of the document<br \/>\n      bool success = ((XmlElement)xml.DocumentElement.SelectSingleNode(&quot;document&quot;)).GetAttribute(&quot;status&quot;) == &quot;true&quot;;<\/p>\n<p>      \/\/ get errors<br \/>\n      if (!success)<br \/>\n      {<br \/>\n        Console.WriteLine(&quot;Document submission failed. Errors below.&quot;);<\/p>\n<p>        foreach (XmlElement error in xml.DocumentElement.SelectNodes(&quot;errors\/error&quot;))<br \/>\n        {<br \/>\n          Console.WriteLine(error.GetAttribute(&quot;description&quot;));<br \/>\n        }<br \/>\n      }<br \/>\n      else<br \/>\n      {<br \/>\n        Console.WriteLine(&quot;Document submitted successfully!&quot;);<br \/>\n      }<br \/>\n    }<br \/>\n[\/code]<\/p>\n<p>That\u2019s it! As you can see, it is pretty straightforward to create the input and call the business process through the web service.<br \/>\nHere is the link to the Visual Studio (2010) solution.<\/p>\n<p><a href=\"https:\/\/syncimprov.com\/wp-content\/uploads\/2014\/02\/lynxdemo3.zip\">LynXDemo<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this post, I&#8217;ll describe how to call a (LynX) business process through the web service. Note: This post assumes that you are calling the web service from .Net. The web service can be called by any external app that &hellip; <a href=\"https:\/\/syncimprov.com\/?p=92\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":147,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[3,9,11,12,17],"class_list":["post-92","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-net","tag-enterpriseone","tag-integration","tag-jde","tag-web-services"],"_links":{"self":[{"href":"https:\/\/syncimprov.com\/index.php?rest_route=\/wp\/v2\/posts\/92","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/syncimprov.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/syncimprov.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/syncimprov.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/syncimprov.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=92"}],"version-history":[{"count":0,"href":"https:\/\/syncimprov.com\/index.php?rest_route=\/wp\/v2\/posts\/92\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/syncimprov.com\/index.php?rest_route=\/wp\/v2\/media\/147"}],"wp:attachment":[{"href":"https:\/\/syncimprov.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=92"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/syncimprov.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=92"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/syncimprov.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=92"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}