I had to do this before support for REST in IPA was possible, basically, create a c# program in visual studio to handle the interaction, execute it and return the results in a System Command node. If I get a bad rc, I report the error text. Branch node in flow handles the return code. This is a lookup into the sam.gov website to see if a vendor is on the active exclusion list for grants.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SAMWSearch.SAMWS1;
using RestSharp;
namespace SAMWSearch
{
public class SAMResult
{
SAMWS1.ExclusionSearchResultType value { get; set; }
}
public class SamResults : List { }
class Program
{
static int Main(string[] args)
{
var client = new RestClient("https://gw.sam.gov/SAMWS/...lusionSearch");
var request = new RestRequest("doSearch", Method.POST);
request.AddParameter("partialName", args[1]);
var results = client.Execute(request);
int result = 999; // 999 = error lookup not performed. 1 - Business excluded, 0 - Business not excluded
Console.WriteLine("results");
result = 1;
return (result);
}
}
}
That was the old one for the REST api in VS2010. Here's the latest one using SOAP (VS2017):
using System;
using System.ServiceModel;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Xml;
using System.IO;
using System.Xml.Serialization;
using System.Net;
using System.Timers;
using System.Threading;
namespace SAMsearch
{
class Program
{
const int C_NOT_EXCLUDED = 0;
const int C_EXCLUDED = 1;
const int C_LOOKUP_NOT_PERFORMED = 999;
///
/// Execute a Soap WebService call
///
public static int Execute(string parm)
{
int result = C_LOOKUP_NOT_PERFORMED; // 1 - Excluded, Do Not Award Contract without first doing manual lookup.
HttpWebRequest request = CreateWebRequest();
XmlDocument soapEnvelopeXml = new XmlDocument();
string xml = @"
http://www.w3.org/2001/XM...instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema"" xmlns:soap=""http://schemas.xmlsoap.or...nvelope/"" xmlns:ns1=""http://www.sam.gov"">
";
xml = xml + parm;
xml = xml + @"
";
// JOE* ALLEN* GORDON*
//BEST BUY
soapEnvelopeXml.LoadXml(xml);
using (Stream stream = request.GetRequestStream())
{
soapEnvelopeXml.Save(stream);
}
using (WebResponse response = request.GetResponse())
{
using (StreamReader rd = new StreamReader(response.GetResponseStream()))
{
string soapResult = rd.ReadToEnd();
Console.WriteLine(soapResult);
// If the following string is included in the response, the company is not exluded.
int index = soapResult.IndexOf("No records foundtrue");
if (index < 0) { result = C_EXCLUDED; } else { result = C_NOT_EXCLUDED; }
}
}
return (result);
}
///
/// Create a soap webrequest to [Url]
///
///
public static HttpWebRequest CreateWebRequest()
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(@"https://gw.sam.gov/SAMWS/...lusionSearch");
webRequest.Headers.Add(@"SOAP:Action");
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
return webRequest;
}
public static void help()
{
Console.WriteLine("SAM90W: No business name specified."); // Console.ReadKey();
Console.WriteLine("SAM01I: Information");
Console.WriteLine(" Purpose: Looks up a business name in the SAM Exclusion List at gw.sam.gov.");
Console.WriteLine(" Prints results and returns a code: 0 = Not Excluded, 1 = Not Excluded,");
Console.WriteLine(" or 999=Lookup not performed with error messages printed.\n");
Console.WriteLine(" Format: SAMsearch [Business Name]\n");
Console.WriteLine(" Example: SAMsearch \"JOE ALLEN GORDON\"");
Console.WriteLine(" on 2/20/2014 this returns 1 = excluded.\n");
Console.WriteLine(" Example2: SAMsearch \"JOE GORDON\"");
Console.WriteLine(" on 2/20/2014 this also returns 1 = excluded.\n");
Console.WriteLine(" Example3: SAMsearch \"JOE MARTIN GORDON\"");
Console.WriteLine(" on 2/20/2014 this returns 0 = not excluded.\n");
}
static int Main(string[] args)
{
int result = 999; // 999 err - lookup not performed. 1 - Business excluded: do not award, 0 - Business not excluded.
Console.WriteLine("SAMsearch 2.1 2/11/2015.");
if ( args.Length > 0)
{
if (args[0].Length > 0)
{
string parm_company_name = args[0].ToUpper();
parm_company_name = parm_company_name.Replace("&", "&");
parm_company_name = parm_company_name.Replace("<", "<");
parm_company_name = parm_company_name.Replace(">", ">");
parm_company_name = parm_company_name.Replace("'", "'");
parm_company_name = parm_company_name.Replace("\"", """);
Console.WriteLine("SAM03I Looking up: '{0}' in SAM EPLS.EPLS.", parm_company_name);
result = Execute(parm_company_name);
}
else
{
help();
}
}
else
{
help();
}
return (result);
}
}
}