我正在尝试在 C# 项目中使用 ServiceReference。该项目旨在测试连接。我有一个客户正在尝试将 C# 应用程序连接到我的一位同事的一项 Web 服务。无法建立连接,他认为这是我们自己的错误。
我现在正在尝试编写一个简单的 C# 项目。故事已经够多了……现在需要的信息。
- 客户使用代理服务器
- 出于测试原因,我尝试连接到此 Web 服务 http://www.w3schools.com/webservices/tempconvert.asmx
- 我使用 .Net Framework 4.0
- 我的项目编译成一个 Windows 窗体应用程序。
这里是我的方法的源代码:
    private void button2_Click(object sender, EventArgs e)
    {
        try
        {
            //Create Client
            ServiceReference1.TempConvertSoapClient client = new ServiceReference1.TempConvertSoapClient(@"TempConvertSoap",@"http://www.w3schools.com/webservices/tempconvert.asmx");
            if (client.ClientCredentials != null)
            {
                //Use Values which are typed in in the GUI
                string user = tbUser.Text;
                string password = tbPassword.Text;
                string domain = tbDomain.Text;
                //Check what information is used by the customer.
                if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(domain))
                {
                    client.ClientCredentials.Windows.ClientCredential = new NetworkCredential(user, password, domain);
                }
                if (!string.IsNullOrEmpty(user) && !string.IsNullOrEmpty(password))
                {
                    client.ClientCredentials.Windows.ClientCredential = new NetworkCredential(user, password);
                }
            }
            //Oh nooo... no temperature typed in
            if (string.IsNullOrEmpty(tbFahrenheit.Text))
            {
                //GOOD BYE
                return;
            }
            //Use the webservice 
            string celsius =  client.FahrenheitToCelsius(tbFahrenheit.Text); //<-- Simple Calculation
            tbCelsius.Text = celsius;
        }
        catch(Exception ex) 
        {
            //Something 
            MessageBox.Show(ex.ToString());
        }
    }
这是我的问题: 如何设置此服务引用或客户端的代理?没有用于此目的的属性或设置器。我用 ClientCredentials 试过了