473,382 Members | 1,420 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

WebService-Requests over a proxy server

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
Apr 19 '06 #1
3 7435
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" wrote:
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

Apr 19 '06 #2
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 [C# MVP]" <pb*******@yahoo.nospammin.com> wrote in message
news:F4**********************************@microsof t.com...
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" wrote:
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

Apr 19 '06 #3
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

Peter Bromberg [C# MVP] schrieb:
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

Apr 20 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: MA | last post by:
Hi all! I know there is other newsgroups for webservices, but I donīt get any answers on those. I have developed a webservice that writeing and reading files in different folders. Question...
0
by: Thijs | last post by:
Hi, I am developing both a webservice and a Windows Forms webservice client. After I've deployed my webservice to the webserver I update my webservice reference in my client application, but the...
11
by: Andy | last post by:
Make the story short, I have a VB.NET client interface calling .NET webservice, written in VB.NET as well. I am trying to make the client as thin as possible so I let the webservice part to...
8
by: Topper | last post by:
Hello. I have simple web folders structure: -ROOT - BIN WebService.dll WebService.asmx I need to use my WebService.dll not in bin folder - for example, in ROOT. How do i this? How can i do...
8
by: kenneth fleckenstein nielsen | last post by:
hi guru's I want to restart my webservice when ever it throws an exception that isn't cought. can i do that by web.config or iss or how ??
5
by: | last post by:
Hi, How long do webservice objects live for? In particular, if i have static variables filled with data from a static constructor in a webservice, how long will that data persist? thxs
1
by: batista | last post by:
Hi, I'm using webservice.htc to call a non-secure(without https) webservice method from a webpage. Now, if the webpage is not under https then everything works fine. But, when enable ssl in...
0
by: batista | last post by:
Hello all, I am using a webpage having a grid and im calling a webservice method(using webservice.htc) which after 5 seconds updates the content of the grid, uptil now everything is working...
0
by: =?Utf-8?B?TWFuaQ==?= | last post by:
Hi All, Problem in deploying my WebService developed using Asp.net WebServices 2005. I have designed simple WebService using Asp.net Webservices 2.0 , The webservice look this , using System;...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.