One of the components of SmartConnect is the WCF REST service that may be installed on a machine where IIS is also installed. This document is a series of KnowledgeBase Articles that are written to show how the use and execute existing SmartConnect API methods.

runmap

The runmap method allows you to run a map from your application or website. This would be the equivalent to running the map from within the SmartConnect user interface or on a schedule.

 

Map Setup

Create the map as you would any other map within SmartConnect.

You will not be able to run Real-Time maps from a WCF REST method call.

 

URL

The URL to call will be based on the server where the SmartConnect WCF REST Web Service was installed. The default Port for the SmartConnect WCF REST service is 5557 but can be changed in IIS as desired.

For example.

http://myserver:5557/smartconnect.svc/runmap/MYMAP

Review the documentation on setting up the SmartConnect WCF REST Web Service. https://www.eonesolutions.com/Manuals/SmartConnect/SmartConnect%202018/?page=sc_configure_wcf_rest_service

 

Variables

With the runmap method, you can pass variables into the map but the URL will change slightly as well as the payload.

http://myserver:5557/smartconnect.svc/runmap/var/MYMAP

The payload for the map will be the following where the GBL_VARIABLE_NAME would be set to the global variable being used in the map

<ArrayOfVariableOfstringstring xmlns=http://schemas.datacontract.org/2004/07/eOne.SmartConnect.Enginexmlns:i=http://www.w3.org/2001/XMLSchema-instance>

<VariableOfstringstring>

<Key>GBL_VARIABLE_NAME</Key>

<Value>My Value</Value>

</VariableOfstringstring>

<VariableOfstringstring>

<Key>GBL_VARIABLE_NAME_TWO</Key>

<Value>My Value</Value>

</VariableOfstringstring>

</ArrayOfVariableOfstringstring>

Return Result

The results of the map run will be returned in an XML format.

<RunMapResponse>

<ErrorCount>0</ErrorCount>

<ErrorMessage/>

<Errors/>

<MapDescription>Send Data to ERP</MapDescription>

<MapId>MYMAP</MapId>

<RecordCount>11</RecordCount>

<RunNumber>21</RunNumber>

<Status>Successful</Status>

</RunMapResponse>

 

NOTE: The < > symbols will actually come back as &lt; &gt; . This means we need to replace those values with the actual less than/greater than values in the return string.

result.Replace(“&gt;”, “>”).Replace(“&lt;”, “<“);

 

Sample Code

Below is sample C# code that you can use to execute your map from your application or web site, using the GET method since we are not posting any data in the body.

try

{

var httpWebRequest = (HttpWebRequest)WebRequest.Create(“http://myserver:5557/smartconnect.svc/runmap/MYMAP“);

httpWebRequest.Credentials = new NetworkCredential(“User”, “Password”, “Domain”);

httpWebRequest.Method = “GET”;

 

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

 

string result = string.Empty;

using (var responseStream = new StreamReader(httpResponse.GetResponseStream()))

{

result = responseStream.ReadToEnd();

}


// load the results into an XML document to save it to a file

var doc = new System.Xml.XmlDocument();

doc.LoadXml(result);

 

// or display the results to the user

MessageBox.Show(result.Replace(“&gt;”, “>”).Replace(“&lt;”, “<“));

}

catch (WebException ex)

{

MessageBox.Show(ex.ToString());

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString());

}

finally

{

}

 

In this example, we using the POST method and including the list of global variables as the payload to the call.

try

{

// Build the payload with the global variable and the value

 

System.Text.StringBuilder payload = new System.Text.StringBuilder(250);

 

payload.Append(“<ArrayOfVariableOfstringstring xmlns=”http://schemas.datacontract.org/2004/07/eOne.SmartConnect.Engine” “);

 

payload.Append(“xmlns:i=”http://www.w3.org/2001/XMLSchema-instance”><VariableOfstringstring>”);

 

payload.Append(“<Key>GBL_JOURNAL_NUMBER<Key><Value>123346</Value>”);

 

payload.Append(“</VariableOfstringstring></ArrayOfVariableOfstringstring>”);

 

 

var httpWebRequest = (HttpWebRequest)WebRequest.Create(“http://myserver:5557/smartconnect.svc/runmap/var/MYMAP“);

httpWebRequest.Credentials = new NetworkCredential(“User”, “Password”, “Domain”);

httpWebRequest.Method = “POST”;

httpWebRequest.ContentLength = payload.Length;

 

using (var reqStream = httpWebRequest.GetRequestStream())

{

reqStream.Write(Encoding.ASCII.GetBytes(payload.ToString()), 0, payload.Length);

}

 

var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();

 

string result = string.Empty;

using (var responseStream = new StreamReader(httpResponse.GetResponseStream()))

{

result = responseStream.ReadToEnd();

}


// load the results into an XML document to save it to a file

var doc = new System.Xml.XmlDocument();

doc.LoadXml(result);

 

// or display the results to the user

MessageBox.Show(result.Replace(“&gt;”, “>”).Replace(“&lt;”, “<“));

}

catch (WebException ex)

{

MessageBox.Show(ex.ToString());

}

catch (Exception ex)

{

MessageBox.Show(ex.ToString());

}

finally

{

}

 

Map

The global variable that is passed into the map using the runmap method can be used in a Pre-Map task. It could be used to restrict a query on SQL or CRM or Salesforce data source, as an example. Below I have set up a SQL data source that would use a passed in value to restrict the data query to the provided value from the runmap execution.

 

 

Additional Notes

  • The map runs on the IIS Server
    • Any Errors will also be logged in the SmartConnect Event Viewer on the IIS Server
    • Access to files, either as the source or destination, will be from the IIS Server. Ensure the correct path exists and is accessible from this server
    • The Map is executed in the context of the user assigned to the Web Service Application Pool.