Click Here to Install Silverlight*
United StatesChange|All Microsoft Sites|Sign in
Microsoft
|Communities Home|Communities Worldwide
  IWebProxy and the SystemProxy in Web Services  
 |  Edit my Profile  |  Help
 
     
  
 
 
 
cisco man 2/15/2007 12:50 PM PST
  Question
 
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!

 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Steven Cheng[MSFT] 2/15/2007 11:48 PM PST
  Answer
  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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.

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



This posting is provided "AS IS" with no warranties, and confers no rights
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
cisco man 2/20/2007 6:22 PM PST
   
  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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx.
>
> ==================================================
>
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
 
 
Steven Cheng[MSFT] 2/20/2007 6:35 PM PST
   
  You're welcome :)

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
 
  Was this post helpful to you?  
 
 
  Reply | Print post   TopTop  
 
 
  Return to Microsoft Communities  Notify me of replies  
 
Windows Live ID

© 2009 Microsoft Corporation. All rights reserved. Contact Us |Terms of Use |Trademarks |Privacy Statement