Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > .NET General

Vista - .Net 2.0 issue with HttpWebRequest/Proxy breaking WebService

Reply
 
Old 05-12-2008   #1 (permalink)
LarryKuperman


 
 

.Net 2.0 issue with HttpWebRequest/Proxy breaking WebService

Our WebDev team is experiencing a problem when trying to access a WebService
using SSL and through a proxy server after using the HttpWebRequest object.
Under normal circumstances we are 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(using 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 webServiceObject = new YourWebService();

//Set Credentials for Web Service
webServiceObject.Credentials = new
System.Net.NetworkCredential("username", "password", "domain");

//Call a method from the Web Service. This Call works without
any errors.
object returnObject = webServiceObject.anyWebServiceMethod();

//Create HttpWebRequest Object to any non secure web page
HttpWebRequest webRequestObject =
(HttpWebRequest)HttpWebRequest.Create("http://www.microsoft.com/");
//Call GetResponse
HttpWebResponse testRes =
(HttpWebResponse)webRequestObject.GetResponse();

//Call the same method from the Same Web Service Object. This
call will fail.
returnObject = webServiceObject.anyWebServiceMethod();

//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.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
//at
System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String
methodName, Object[] parameters)
//at Proxy.[snip].Service.ValidateAccount(String email, String
password, OperatingSystemInfo osInfo) in
C:\Projects\Sandbox\CSharp\ProxyTest\Web References\[snip]\Reference.cs:line
336
//at Proxy.Form1.Form1_Load(Object sender, EventArgs e) in
C:\Projects\Sandbox\CSharp\ProxyTest\Form1.cs:line 38
//at System.Windows.Forms.Form.OnLoad(EventArgs e)
//at System.Windows.Forms.Form.OnCreateControl()
//at System.Windows.Forms.Control.CreateControl(Boolean
fIgnoreVisible)
//at System.Windows.Forms.Control.CreateControl()
//at System.Windows.Forms.Control.WmShowWindow(Message& m)
//at System.Windows.Forms.Control.WndProc(Message& m)
//at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
//at System.Windows.Forms.ContainerControl.WndProc(Message& m)
//at System.Windows.Forms.Form.WmShowWindow(Message& m)
//at System.Windows.Forms.Form.WndProc(Message& m)
//at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
//at
System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
//at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr
hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
//at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef
hWnd, Int32 nCmdShow)
//at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
//at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
//at System.Windows.Forms.Control.set_Visible(Boolean value)
//at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
//at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
//at System.Windows.Forms.Application.Run(Form mainForm)
//at Proxy.Program.Main() in
C:\Projects\Sandbox\CSharp\Proxy\Proxy\Program.cs:line 17
//at System.AppDomain.nExecuteAssembly(Assembly assembly,
String[] args)
//at System.AppDomain.ExecuteAssembly(String assemblyFile,
Evidence assemblySecurity, String[] args)
//at
Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
//at System.Threading.ThreadHelper.ThreadStart_Context(Object
state)
//at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
//at System.Threading.ThreadHelper.ThreadStart()

Please advise how we can solve this issue.

--
Larry Kuperman
Global Account Manager
Stardock- A Microsoft Gold Partner

My System SpecsSystem Spec
Old 02-22-2009   #2 (permalink)


Win 2003
 
 

Re: .Net 2.0 issue with HttpWebRequest/Proxy breaking WebService

Hello Larry,

I have got same kind of problem few days back. To fix the issue, check below.

The issue:
I created sample application which GETs google logo through HTTP web request in first place and then call one sample asp.net web-service through HTTP POST method. Surprisingly, in Fiddler, I found Google page not found error-page for the second asp.net web-service call. And vice versa, if asp.net web-service is called in first place, I got asp.net page not found error-page for the google logo request. i.e. first good connection was used for consecutive web calls in the same application life cycle.

Reason:
The default ‘Keep Alive’ in web-service call or in HTTP web request (that we do for file downloads) is true, meaning the same TCP connection will be used for all requests be it web-service or HTTP calls.

Fix:
Set KeepAlive as false in all HTTP web requests. For web service calls, you may want to create partial class with the same name/namespace as web-proxy class. Override OnGetHttpRequest and assign keepalive to false. Sample is below.

namespace Namespace-in-which-proxy-webservice-class-is-located
{
public partial class Web-Service-Proxy-Class-Generated-by-VS
{
protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest request = base.GetWebRequest(uri) as HttpWebRequest;
request.KeepAlive = false;
return request;
}
}
}


It works at my end. I hope it would be helpful.

Thanks!
Dhananjay
dgoyani at gmail dot com
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
suspect proxy setting issue Vista networking & sharing
HttpWebRequest won't work in PowerShell without a Proxy PowerShell
IE Proxy Issue Vista General


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46