如何通过C#中经过身份验证的代理服务器访问SOAP服务?

时间:2017-12-18 16:15:03

标签: c# web-services wcf soap proxy

首先让我说我是C#和SOAP服务的新手。我需要拧一个程序来读取平面文件中的数据,并调用SOAP Web服务将数据插入到该系统中。

我的网络位于代理服务器后面,我必须使用用户名和密码进行身份验证才能访问我们网络外部或互联网上的任何内容。我无法弄清楚如何做到这一点。我一直在寻找答案并尝试我找到的结果,但我没有运气。我得到的错误信息是

  

"请求失败并显示空响应"

我已经在SOAPUI中设置了服务,如果我将我的代理设置提供给SOAPUI首选项,它就可以离开我们的网络并获得响应。

我在下面的示例中使用的用户名和密码不是真实的,但响应无论如何都不会改变。在我看来,它似乎永远不会尝试通过代理服务器进行访问或身份验证。

任何人都可以帮助我吗?谢谢。

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            ConsoleApp6.ASC.Service1 soap = new ConsoleApp6.ASC.Service1();
            ConsoleApp6.ASC.UserCredentialsSoapHeader credential = new ConsoleApp6.ASC.UserCredentialsSoapHeader();           
            credential.UserName = "soap_user_name";
            credential.Password = "soap_password";
            soap.UserCredentialsSoapHeaderValue = credential;

            soap.Proxy = new WebProxy("http://gateway.zscalertwo.net:80/", true);
            soap.Proxy.Credentials = new NetworkCredential("username", "password", "domain");


            try
            {
                ASC.AppraiserLicense licenceInfo = soap.GetLicenseByLicenseNumber("46000049784", 1, "NY");
                Console.WriteLine(licenceInfo);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            Console.ReadLine();
        }
    }
}

Console Output

  

System.Net.WebException:请求因空响应而失败   在   System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClie   ntMessage消息,WebResponse响应,流responseStream,   布尔asyncCal l)at   System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(字符串   methodN ame,Object [] parameters)at   ConsoleApp6.ASC.Service1.GetLicenseByLicenseNumber(字符串   LicenseNumber,B yte LicType,String st_abbr)in   C:\ Users \ mkurick \ Documents \ Visual Studio 2017 \ Pr   ojects \ ConsoleApp6 \ ConsoleApp6 \ Web References \ ASC \ Reference.cs:line   120在ConsoleApp6.Program.Main(String [] args)中   C:\ Users \ mkurick \ Documents \ Visu al Studio   2017 \ Projects \ ConsoleApp6 \ ConsoleApp6 \ Program.cs:第26行

0 个答案:

没有答案