Getting : The handshake failed due to an unexpected packet format exception while accessing Microsoft SharePoint 2010 from ASP.NET 4.0 application

Yesterday I encountered strange thing when accessing SharePoint 2010.

What I had :

I created some time ago ASP.NET application for uploading file to SharePoint 2007. Our company upgraded the SharePoint to latest 2010, so I had to update my tool also. It used ASP.NET 3.5. Internally we are using Forefront and I have Forefront client installed on my dev box. Everything worked fine. (I’m not sure, if the Forefront client is installed also the server, but I suppose so).

What was the problem :

After migration to ASP.NET 4.0, my code wasn’t working. When calling Lists.UpdateListItems on web service generated proxy class, I got nice System.Net.WebException The underlying connection was closed: An unexpected error occurred on a send exception with underling The handshake failed due to an unexpected packet format exception. So I created small console app and the code was working again (I used same library in the ASP.NET app and also in console app). But the ASP.NET app wasn’t.

Exception looked like this :

system.net.webexception

Also as I saw, it had to do something with SSL certificates.

Desperate, I fired up Fiddler, my tool of choice for HTTP traffic debugging and ASP.NET page started to work without any code change. Then it hit me : proxy problem.

The solution :

The Forefront client is set so, it will direct any app to either use our proxy server, or go directly to the server inside of our organization. In my case the ASP.NET app tried to use proxy settings and called the Sharepoint server via proxy and I would say, something messed up the SSL certificates. Anyway, you just have to say to your app, that it shouldn’t use proxy and this can be done in code, or in web.config (respectively app.config). I used this approach. How to set proxy in web.cofign file can be found here : http://msdn.microsoft.com/en-us/library/kd3cf2ex.aspx

Enjoy. 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *