WebService-Requests over a proxy server

  • Thread starter Thread starter Thomas Klein
  • Start date Start date
T

Thomas Klein

Hello NG,

I want to realize that my C# software is able to send its
webservice-requests over the company's proxy server. In Java I've solved
this in that way:

System.setProperty("proxySet", "true");
System.setProperty("http.proxyHost", proxyHost);
System.setProperty("http.proxyPort", proxyPort);

Is there in C# an equivalent way to do the same? I would be happy if
someone could help me! Thanks in avance!

Bye
Thomas
 
Thomas,
here is some sample code to get you started:


WebProxy p = null;
string proxyAddressAndPort =
ConfigurationSettings.AppSettings["proxy"];
string proxyUserName =
ConfigurationSettings.AppSettings["proxyUserName"];
string proxyPassword =
ConfigurationSettings.AppSettings["proxyPassword"];
ICredentials cred;
cred = new NetworkCredential(proxyUserName, proxyPassword);
p = new WebProxy(proxyAddressAndPort, true, null, cred);
GlobalProxySelection.Select = p;

Hope that helps.
Peter
 
Or directly from the webservice itself
My.Fully.QualifiedNameSpace.WebService service = new
My.Fully.QualifiedNameSpace.WebService();
WebProxy p = null;
string proxyAddressAndPort = ConfigurationSettings.AppSettings["proxy"];
string proxyUserName = ConfigurationSettings.AppSettings["proxyUserName"];
string proxyPassword = ConfigurationSettings.AppSettings["proxyPassword"];
ICredentials cred = new NetworkCredential(proxyUserName, proxyPassword);
p = new WebProxy(proxyAddressAndPort, true, null, cred);
service.Proxy = p;



Peter Bromberg said:
Thomas,
here is some sample code to get you started:


WebProxy p = null;
string proxyAddressAndPort =
ConfigurationSettings.AppSettings["proxy"];
string proxyUserName =
ConfigurationSettings.AppSettings["proxyUserName"];
string proxyPassword =
ConfigurationSettings.AppSettings["proxyPassword"];
ICredentials cred;
cred = new NetworkCredential(proxyUserName, proxyPassword);
p = new WebProxy(proxyAddressAndPort, true, null, cred);
GlobalProxySelection.Select = p;

Hope that helps.
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Thomas Klein said:
Hello NG,

I want to realize that my C# software is able to send its
webservice-requests over the company's proxy server. In Java I've solved
this in that way:

System.setProperty("proxySet", "true");
System.setProperty("http.proxyHost", proxyHost);
System.setProperty("http.proxyPort", proxyPort);

Is there in C# an equivalent way to do the same? I would be happy if
someone could help me! Thanks in avance!

Bye
Thomas
 
Thank you for your response! I've tried out in this way, but the
application does not use my proxy anyway:

public class MySettings {

public WebProxy p;

public void initializeProxySettings()
{
this.p = null;
string proxyHost = ConfigurationSettings.AppSettings["proxyHost"];
string proxyPort = ConfigurationSettings.AppSettings["proxyPort"];
string proxyUserName =
ConfigurationSettings.AppSettings["proxyUserName"];
string proxyPassword =
ConfigurationSettings.AppSettings["proxyPassword"];
ICredentials cred;
cred = new NetworkCredential(proxyUserName, proxyPassword);
p = new WebProxy(proxyHost + ":" + proxyPort, true, null, cred);
GlobalProxySelection.Select = p;
}

}

In another class, I send my webservice-request by a helper class
(CmHelper) which inherits from the class MySettings:

try {
String url = this.cmHelper.GetURL(param1,param2);
} catch (Exception e) {
System.Console.Out.WriteLine("An Exception occured
while sending the request to the CityMapService!");
System.Console.Out.WriteLine(e.Message);
System.Console.Out.WriteLine(e.StackTrace);
}

Can someone tell me what I have done wrong?
Thanks in advice!

Thomas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top