469,336 Members | 5,156 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

IWebProxy and the SystemProxy


Just have some general questions on how it's supposed to work. When i get
WebREquest.GetSystemWebPRoxy it returns a
System.Net.WebRequest+WebProxyWrapperOpaque type. Which doesn't have any
public property to set useDefaultCredentials. I assign this to the ws proxy
and set the UseDefaultCredentials, on the proxy object, to true. This
doesn't seem to work when dealing with a proxy that is using ISA server and
validating credentials with the domain. Is this the proper way of doing this?
Why do i need to create a WebProxy object if the SystemProxy being returned
has it all. It just seems like if i could set that property on the proxy
object itself, it would work

So i end up doing something like [1] as well as have the user type it in
if he/she wants to.
Uri uriFromProxy = systemProxy.GetProxy(uriToProbe);
if( uriToProbe != uriFromProxy ) {
// real proxy is set so i can get the port/address from the
UriFromProxy
WebProxy proxyObject = new WebProxy(addressWithPort, true);
proxyObject.UseDefaultCredentials = true;
}

I guess what i'm asking is what is the proper way of handling proxy
server's, in general, with web services? MS seems to release a lot of
general practices but i think i missed this one.

Thanks!
Feb 15 '07 #1
3 11248
Hello cisco man,

As for the WebRequest.GetSystemWebPRoxy it does return a
"System.Net.WebRequest+WebProxyWrapperOpaque" type which is internal.
Actually, when using the returned object from WebRequest.GetSystemWebProxy
method, you're always suggested to use the "IWebProxy" interface as that
interface has provide all the necessary properties.

For the "useDefaultCredentials" property of WebProxy class, it simply
assign the corresponding credentials to the IWebProxy.Credentials
property(according to the given value). Here is the diassembed code from
reflector:

=====from WebProxy class======
public bool UseDefaultCredentials
{
get
{
if (!(this.Credentials is SystemNetworkCredential))
{
return false;
}
return true;
}
set
{
this._Credentials = value ? CredentialCache.DefaultCredentials
: null;
}
}

public ICredentials Credentials
{
get
{
return this._Credentials;
}
set
{
this._Credentials = value;
}
}
================

therefore, the setting "UseDefaultCredentials" of WebProxy to true is
identical to the following code (for IWebProxy):

=======================
IWebProxy proxy = WebRequest.GetSystemWebProxy();

proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
=======================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 16 '07 #2
Steven,

Thanks for the post. I did use reflector but didn't bother looking at the
implementation of UseDefaultCredentials. Once i set it to the
DefaultCredentials everything worked fine.

The only thing that bothers me is that i'm relying on that implementation
but i guess it makes sense that setting the ICredential property to the
DefaultCredentials would force it to this. Even if it didn't it will still
use the default creds anyway. Thanks again!
Thanks again,
Cisco

"Steven Cheng[MSFT]" wrote:
Hello cisco man,

As for the WebRequest.GetSystemWebPRoxy it does return a
"System.Net.WebRequest+WebProxyWrapperOpaque" type which is internal.
Actually, when using the returned object from WebRequest.GetSystemWebProxy
method, you're always suggested to use the "IWebProxy" interface as that
interface has provide all the necessary properties.

For the "useDefaultCredentials" property of WebProxy class, it simply
assign the corresponding credentials to the IWebProxy.Credentials
property(according to the given value). Here is the diassembed code from
reflector:

=====from WebProxy class======
public bool UseDefaultCredentials
{
get
{
if (!(this.Credentials is SystemNetworkCredential))
{
return false;
}
return true;
}
set
{
this._Credentials = value ? CredentialCache.DefaultCredentials
: null;
}
}

public ICredentials Credentials
{
get
{
return this._Credentials;
}
set
{
this._Credentials = value;
}
}
================

therefore, the setting "UseDefaultCredentials" of WebProxy to true is
identical to the following code (for IWebProxy):

=======================
IWebProxy proxy = WebRequest.GetSystemWebProxy();

proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
=======================

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

==================================================

This posting is provided "AS IS" with no warranties, and confers no rights
Feb 21 '07 #3
You're welcome :)

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Feb 21 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Bill Hauver | last post: by
6 posts views Thread by Prehaut Anselme | last post: by
10 posts views Thread by Abubakar | last post: by
3 posts views Thread by Pritam Bhat | last post: by
6 posts views Thread by Daniel Santana | last post: by
3 posts views Thread by =?Utf-8?B?SmFsaWw=?= | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.