Our WebDev team seems to have found a problem that exposes a bug in .NET 2.0.
This problem can be shown when trying to access a WebService using SSL and
through a proxy server after using the HttpWebRequest object.
Under normal circumstances I am able to use the webservice without any
problems. But after using an HttpWebRequest object to make a call to a
website
all subsequent attempts to use the WebService will fail with a 401
Unauthorized error. This problem appears to be directly related to when the
Client's Internet Explorer settings are configured to use a Proxy server for
http requests. If the settings for the proxy server are disabled everything
works as expected.
Server Configuration:
Windows 2003 Server Service Pack 2
IIS 6.0, Using SSL Port 443, Anonymous access disabled, using Integrated
Windows Authentication
..Net 2.0
Client:
Windows XP Service Pack 2
..Net 2.0
IE 7, configured to use a proxy server
Below is sample code that can be used to reproduce the problem with a CSharp
Windows Application.
//PreRequisites: Webservice must be using SSL (https) and does
not allow anoymous connections(usi ng Integrated Windows Authentication)
//Client's IE Settings requires http requests to go through a
Proxy server. (If proxy is not enabled the below scenario works properly)
//Create Web Service Object
YourWebService webServiceObjec t = new YourWebService( );
//Set Credentials for Web Service
webServiceObjec t.Credentials = new
System.Net.Netw orkCredential(" username", "password", "domain");
//Call a method from the Web Service. This Call works without
any errors.
object returnObject = webServiceObjec t.anyWebService Method();
//Create HttpWebRequest Object to any non secure web page
HttpWebRequest webRequestObjec t =
(HttpWebRequest )HttpWebRequest .Create("http://www.microsoft.c om/");
//Call GetResponse
HttpWebResponse testRes =
(HttpWebRespons e)webRequestObj ect.GetResponse ();
//Call the same method from the Same Web Service Object. This
call will fail.
returnObject = webServiceObjec t.anyWebService Method();
//The Above call will fail with the following error
//"The request failed with HTTP status 401: Unauthorized."
//Sample Stack Trace of the error
//at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadRes ponse(SoapClien tMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
//at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Invoke( String
methodName, Object[] parameters)
//at Proxy.[snip].Service.Valida teAccount(Strin g email, String
password, OperatingSystem Info osInfo) in
C:\Projects\San dbox\CSharp\Pro xyTest\Web References\[snip]\Reference.cs:l ine
336
//at Proxy.Form1.For m1_Load(Object sender, EventArgs e) in
C:\Projects\San dbox\CSharp\Pro xyTest\Form1.cs :line 38
//at System.Windows. Forms.Form.OnLo ad(EventArgs e)
//at System.Windows. Forms.Form.OnCr eateControl()
//at System.Windows. Forms.Control.C reateControl(Bo olean
fIgnoreVisible)
//at System.Windows. Forms.Control.C reateControl()
//at System.Windows. Forms.Control.W mShowWindow(Mes sage& m)
//at System.Windows. Forms.Control.W ndProc(Message& m)
//at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
//at System.Windows. Forms.Container Control.WndProc (Message& m)
//at System.Windows. Forms.Form.WmSh owWindow(Messag e& m)
//at System.Windows. Forms.Form.WndP roc(Message& m)
//at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
//at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
//at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
//at System.Windows. Forms.SafeNativ eMethods.ShowWi ndow(HandleRef
hWnd, Int32 nCmdShow)
//at System.Windows. Forms.Control.S etVisibleCore(B oolean value)
//at System.Windows. Forms.Form.SetV isibleCore(Bool ean value)
//at System.Windows. Forms.Control.s et_Visible(Bool ean value)
//at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
//at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32 reason,
ApplicationCont ext context)
//at System.Windows. Forms.Applicati on.Run(Form mainForm)
//at Proxy.Program.M ain() in
C:\Projects\San dbox\CSharp\Pro xy\Proxy\Progra m.cs:line 17
//at System.AppDomai n.nExecuteAssem bly(Assembly assembly,
String[] args)
//at System.AppDomai n.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurit y, String[] args)
//at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
//at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
//at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
//at System.Threadin g.ThreadHelper. ThreadStart()
Please do not hesitate to contact me if you require any additional
information or if you have a solution.
--
Larry Kuperman
Global Account Manager
Stardock- A Microsoft Gold Partner
This problem can be shown when trying to access a WebService using SSL and
through a proxy server after using the HttpWebRequest object.
Under normal circumstances I am able to use the webservice without any
problems. But after using an HttpWebRequest object to make a call to a
website
all subsequent attempts to use the WebService will fail with a 401
Unauthorized error. This problem appears to be directly related to when the
Client's Internet Explorer settings are configured to use a Proxy server for
http requests. If the settings for the proxy server are disabled everything
works as expected.
Server Configuration:
Windows 2003 Server Service Pack 2
IIS 6.0, Using SSL Port 443, Anonymous access disabled, using Integrated
Windows Authentication
..Net 2.0
Client:
Windows XP Service Pack 2
..Net 2.0
IE 7, configured to use a proxy server
Below is sample code that can be used to reproduce the problem with a CSharp
Windows Application.
//PreRequisites: Webservice must be using SSL (https) and does
not allow anoymous connections(usi ng Integrated Windows Authentication)
//Client's IE Settings requires http requests to go through a
Proxy server. (If proxy is not enabled the below scenario works properly)
//Create Web Service Object
YourWebService webServiceObjec t = new YourWebService( );
//Set Credentials for Web Service
webServiceObjec t.Credentials = new
System.Net.Netw orkCredential(" username", "password", "domain");
//Call a method from the Web Service. This Call works without
any errors.
object returnObject = webServiceObjec t.anyWebService Method();
//Create HttpWebRequest Object to any non secure web page
HttpWebRequest webRequestObjec t =
(HttpWebRequest )HttpWebRequest .Create("http://www.microsoft.c om/");
//Call GetResponse
HttpWebResponse testRes =
(HttpWebRespons e)webRequestObj ect.GetResponse ();
//Call the same method from the Same Web Service Object. This
call will fail.
returnObject = webServiceObjec t.anyWebService Method();
//The Above call will fail with the following error
//"The request failed with HTTP status 401: Unauthorized."
//Sample Stack Trace of the error
//at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.ReadRes ponse(SoapClien tMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
//at
System.Web.Serv ices.Protocols. SoapHttpClientP rotocol.Invoke( String
methodName, Object[] parameters)
//at Proxy.[snip].Service.Valida teAccount(Strin g email, String
password, OperatingSystem Info osInfo) in
C:\Projects\San dbox\CSharp\Pro xyTest\Web References\[snip]\Reference.cs:l ine
336
//at Proxy.Form1.For m1_Load(Object sender, EventArgs e) in
C:\Projects\San dbox\CSharp\Pro xyTest\Form1.cs :line 38
//at System.Windows. Forms.Form.OnLo ad(EventArgs e)
//at System.Windows. Forms.Form.OnCr eateControl()
//at System.Windows. Forms.Control.C reateControl(Bo olean
fIgnoreVisible)
//at System.Windows. Forms.Control.C reateControl()
//at System.Windows. Forms.Control.W mShowWindow(Mes sage& m)
//at System.Windows. Forms.Control.W ndProc(Message& m)
//at System.Windows. Forms.Scrollabl eControl.WndPro c(Message& m)
//at System.Windows. Forms.Container Control.WndProc (Message& m)
//at System.Windows. Forms.Form.WmSh owWindow(Messag e& m)
//at System.Windows. Forms.Form.WndP roc(Message& m)
//at
System.Windows. Forms.Control.C ontrolNativeWin dow.OnMessage(M essage& m)
//at
System.Windows. Forms.Control.C ontrolNativeWin dow.WndProc(Mes sage& m)
//at System.Windows. Forms.NativeWin dow.DebuggableC allback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
//at System.Windows. Forms.SafeNativ eMethods.ShowWi ndow(HandleRef
hWnd, Int32 nCmdShow)
//at System.Windows. Forms.Control.S etVisibleCore(B oolean value)
//at System.Windows. Forms.Form.SetV isibleCore(Bool ean value)
//at System.Windows. Forms.Control.s et_Visible(Bool ean value)
//at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo pInner(Int32
reason, ApplicationCont ext context)
//at
System.Windows. Forms.Applicati on.ThreadContex t.RunMessageLoo p(Int32 reason,
ApplicationCont ext context)
//at System.Windows. Forms.Applicati on.Run(Form mainForm)
//at Proxy.Program.M ain() in
C:\Projects\San dbox\CSharp\Pro xy\Proxy\Progra m.cs:line 17
//at System.AppDomai n.nExecuteAssem bly(Assembly assembly,
String[] args)
//at System.AppDomai n.ExecuteAssemb ly(String assemblyFile,
Evidence assemblySecurit y, String[] args)
//at
Microsoft.Visua lStudio.Hosting Process.HostPro c.RunUsersAssem bly()
//at System.Threadin g.ThreadHelper. ThreadStart_Con text(Object
state)
//at System.Threadin g.ExecutionCont ext.Run(Executi onContext
executionContex t, ContextCallback callback, Object state)
//at System.Threadin g.ThreadHelper. ThreadStart()
Please do not hesitate to contact me if you require any additional
information or if you have a solution.
--
Larry Kuperman
Global Account Manager
Stardock- A Microsoft Gold Partner
Comment