我如何在VS2015中消费WSE Web服务



我正在尝试连接到俄亥俄州查找器服务以获取本地销售税信息。该服务的文档和端点地址可通过:

获得

https://thefinder.tax.ohio.gov/streamlinesalestaxweb/webservice/about.aspx

该服务可以免费使用,但确实需要用户注册。

为了添加服务参考,我遵循以下步骤:

  1. 右键单击引用,然后选择"添加服务参考"
  2. 单击"高级"以打开服务参考设置
  3. 单击"兼容性"部分下的"添加Web Reference"。
  4. 提供了服务端点" https://thefinder.tax.ohio.gov/ohfinderservice/ohfinderservice.asmx",然后单击以发现服务。在URL上找到了OhFinderService,所以我添加了参考。

参考已成功添加,但我缺少用于对服务进行身份验证的WSE对象。

我尝试在"配置"部分下添加以下配置:

<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>

添加了"配置"部分后,我单击了"更新Web Refere",但我没有获得WSE对象。

关于我如何使用VS2015连接到Legacy WSE服务的任何想法?

更新:让WSE对象出现在Visual Studio中,我没有运气。这里的最终目标是连接到服务并获取费率信息。考虑到这一点,我正在沿着试图自己构建肥皂要求的平行道路。到目前为止,当我提出请求时,我会遇到内部服务器错误。该服务的规范可以在上面链接的网站中找到。

这是我随请求发送的XML。

<?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>

这是我用来构建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;
        }
    }
}

这是我调用此代码的方式:

            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();

有人可以在这里指向正确的方向吗?我的猜测是我正在错误地构造请求...

Web服务增强3(WSE 3(没有正式支持,因为Visual Studio 2008。

我们必须安装WSE 3.0,然后手动集成在Visual Studio中。

请使用此链接在VS 2015中访问WSE服务。

相关内容

  • 没有找到相关文章

最新更新