Raghu's SharePoint Corner: SharePoint WebPart Socket Exception

My blog has moved!

You will be automatically redirected to the new address. If that does not occur, visit
and update your bookmarks.

November 17, 2009

SharePoint WebPart Socket Exception

Recently when I was working on a web part which hosts a user control was throwing socket exception. I got stuck with this exception for almost 6hrs and finally figured out the main cause for this exception. It was a simple user control which was making a web request to a website and returning some data. The user control worked perfectly fine when I deploy it in an ASP.Net Application, but when I hosted this user control in SharePoint it started throwing Socket Exception “System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it”.

Initially I thought this may be due to Firewall and have to open up port for that web application but the windows firewall was completely turned off (Not a good way of doing that, you should always open port instead of turning off the firewall). So the next thing I did is tried to access the web request URL from my browser for my surprise the URL worked perfectly fine and returned XML data.

For one instance I was thinking this might be something related to web.config settings for sharepoint web application. So went through various settings of web.Config file. Made the proxy settings entry in the System.Net Section of the web.config file and it worked like charm. Given below are the entires that i made in web.config file.

     <defaultProxy useDefaultCredentials="true">
      <proxy usesystemdefault="False" proxyaddress="ServerName:portNo" bypassonlocal="False" />
I was little bit confused at that instance because I had also specified proxy server settings in IE it didn’t work. Will look out for the correct reason why sharepoint was throwing this exception even after the proxy settings had been made in the browser and will update the post accordingly as of now it solved my issue and thought of posting it here.

No comments: