Reputation: 882
I am trying to connect to the Ohio Finder Service to obtain local sales tax information. The documentation for the service, and the endpoint address are available via:
https://thefinder.tax.ohio.gov/streamlinesalestaxweb/webservice/about.aspx
The service is free to use, but does require a user registration.
In order to add the service reference, I followed these steps:
The reference added successfully but I am missing the WSE object that is used to authenticate to the service.
I tried adding the following configuration under the configuration section:
<webServices>
<soapExtensionImporterTypes>
<add type="Microsoft.Web.Services3.Description.WseExtensionImporter, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</soapExtensionImporterTypes>
<soapServerProtocolFactory type="Microsoft.Web.Services3.WseProtocolFactory, Microsoft.Web.Services3, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</webServices>
After adding the configuration section I clicked on 'Update Web Reference', but I did not get the WSE object.
Any ideas on how I can connect to a legacy WSE service using VS2015?
UPDATE: I am having no luck getting the WSE object to show up in visual studio. The end goal here is to connect to the service and obtain rate information. With that in mind, I am heading down a parallel path of trying to construct the SOAP request myself. Thus far I am getting an internal server error when I place the request. The specification for the service may be found in the site linked above.
Here is the XML that I am sending with my request.
<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:si="http://soapinterop.org/xsd"
xmlns:ns5925="https://thefinder.tax.ohio.gov/OHFinderService/OHFinderService.asmx"
xmlns:wsse="http://schemas.xmlsoap.org/ws/2002/07/secext">
<SOAP-ENV:Header>
<wsse:Security>
<wsse:UsernameToken>
<wsse:Username>MYUSERNAME</wsse:Username>
<wsse:Password Type="wsse: PasswordText">MYPASSWORD</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<GetOHSalesTaxByZipCode xmlns="https://thefinder.tax.ohio.gov/OHFinderService/OHFinderService.asmx">
<PostalCode>43230</PostalCode><SalesAmount>10.00</SalesAmount><SalesDate>4%2f5%2f2018</SalesDate><ReturnMultiple>false</ReturnMultiple>
</GetOHSalesTaxByZipCode>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
Here is the code I am using to build the XML
public class WebServiceHelper
{
public string Url { get; set; }
public string MethodName { get; set; }
public Dictionary<string, string> Params = new Dictionary<string, string>();
public XDocument ResultXML;
public string ResultString;
public WebServiceHelper()
{
}
public WebServiceHelper(string url, string methodName)
{
Url = url;
MethodName = methodName;
}
/// <summary>
/// Invokes service
/// </summary>
public void Invoke()
{
Invoke(true);
}
/// <summary>
/// Invokes service
/// </summary>
/// <param name="encode">Added parameters will encode? (default: true)</param>
public void Invoke(bool encode)
{
string soapStr =
@"<?xml version=""1.0"" encoding=""ISO-8859-1""?>
<SOAP-ENV:Envelope xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:soap=""http://schemas.xmlsoap.org/soap/envelope/""
xmlns:si=""http://soapinterop.org/xsd""
xmlns:ns5925=""https://thefinder.tax.ohio.gov/OHFinderService/OHFinderService.asmx""
xmlns:wsse=""http://schemas.xmlsoap.org/ws/2002/07/secext"">
<SOAP-ENV:Header>
<wsse:Security>
<wsse:UsernameToken>
<wsse:Username>USERNAMEHERE</wsse:Username>
<wsse:Password Type=""wsse: PasswordText"">PASSWORDHERE</wsse:Password>
</wsse:UsernameToken>
</wsse:Security>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<{0} xmlns=""https://thefinder.tax.ohio.gov/OHFinderService/OHFinderService.asmx"">
{1}
</{0}>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(Url);
req.Headers.Add("SOAPAction", "\"https://thefinder.tax.ohio.gov/OHFinderService/" + MethodName + "\"");
req.ContentType = "text/xml;charset=\"utf-8\"";
req.Accept = "text/xml";
req.Method = "POST";
using (Stream stm = req.GetRequestStream())
{
string postValues = "";
foreach (var param in Params)
{
if (encode)
postValues += string.Format("<{0}>{1}</{0}>", HttpUtility.UrlEncode(param.Key), HttpUtility.UrlEncode(param.Value));
else
postValues += string.Format("<{0}>{1}</{0}>", param.Key, param.Value);
}
soapStr = string.Format(soapStr, MethodName, postValues);
using (StreamWriter stmw = new StreamWriter(stm))
{
stmw.Write(soapStr);
}
}
using (StreamReader responseReader = new StreamReader(req.GetResponse().GetResponseStream()))
{
string result = responseReader.ReadToEnd();
ResultXML = XDocument.Parse(result);
ResultString = result;
}
}
}
Here is how I am calling this code:
WebServiceHelper ws = new WebServiceHelper("https://thefinder.tax.ohio.gov/OHFinderService/OHFinderService.asmx", "GetOHSalesTaxByZipCode");
ws.Params.Add("PostalCode", "43230");
ws.Params.Add("SalesAmount", "10.00");
ws.Params.Add("SalesDate", DateTime.Today.ToShortDateString());
ws.Params.Add("ReturnMultiple", "false");
ws.Invoke();
Can anyone point me in the right direction here? My guess is that I am constructing the request incorrectly...
Upvotes: 1
Views: 1536