The underlying connection was closed: The connection was closed unexpectedly

405 views
Skip to first unread message

JC

unread,
Sep 28, 2007, 11:49:14 AM9/28/07
to AdWords API Forum
I'm trying to develop a system to update keywords on Google. When
trying to update a large number of keywords (across several adgroups)
I get the error message "The underlying connection was closed: The
connection was closed unexpectedly".

I'm using Visual Basic.Net in Visual Studio 2005. I'm using the code
generated to call the web services, and have made the following
changes (by inheriting the class and overriding the GetWebRequest()
method):

webRequest.KeepAlive = False
webRequest.Timeout = 10000000
webRequest.CachePolicy = New
Net.Cache.HttpRequestCachePolicy(Net.Cache.HttpRequestCacheLevel.NoCacheNoStore)
webRequest.ProtocolVersion = Net.HttpVersion.Version10

However these don't seem to make any difference. I've also written
some code to retry 3 times when it fails but this just fails at the
same point each time.

One thing that is slightly worrying is the system seems to work fine
when run from my laptop but when I run it from the server it can fail
after calling the updateCriteria method only once. I have a campaign
with 60 adgroups and 350 keywords to send to google. These work first
time everytime on my laptop, but fail everytime (at different points)
on the server. I'm running Windows XP Pro SP2 on my laptop, the
server is Windows Server 2003 SP2.

Is there any other properties I need to set? I'm pretty sure it's
a .Net issue rather than a Google Adwords issue but am posting here in
the hope other people have had the same problem. Could it be a
problem with the configuration on the server?

Albert

unread,
Sep 30, 2007, 4:07:06 AM9/30/07
to AdWords API Forum
HI JC,

Pay attention that the wsdl generated classes by .net inherit from
System.Web.Services.Protocols.SoapHttpClientProtocol.

Make sure to call the base.Dispose() method after using it to release
resources. Or wrap it in a using{} /c#/ block (the equivalent in
VB.NET)

Hope this helps,
Albert

Jesper Ellegaard

unread,
Sep 30, 2007, 5:09:17 AM9/30/07
to AdWords API Forum
I've seen the same thing using C# in VS2005, but using the VS
integrated support for web services ("Web references"), i.e. not using
WebRequest .
I discovered that I only lost connection when breaking execution for a
short while in debug. When avoiding braking, I didn't lose any
connections - not even if I put in several minutes of Thread.Sleep().

Rgds
Jesper

Reply all
Reply to author
Forward
0 new messages