我正在尝试在C#项目中使用ServiceReference。该项目旨在测试连接。我的客户正在尝试使用C#应用程序连接到我的同事的一个Web服务。连接无法建立,他认为这是我们自己的错误。
我现在正在尝试编写一个简单的C#项目。 故事讲到这里就够了...现在需要的信息如下:
我现在正在尝试编写一个简单的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());
}
}
这是我的问题: 如何为此服务引用或客户端设置代理? 没有针对此目的的属性或setter。我尝试使用ClientCredentials。