This error is a big pain, simply because I cannot test solutions redily. On my build machine everything works fine, however having make a release and installed it on a different machine (in a differant building) things start to break because of the following exception:

System.Net.WebException : The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.

now, this doesn't happen on the first time I call a webservice, but a while later - always the second "run" of calls. The problem is I have no idea what webservices are, the code I am using is generated so I can't realy modify it much...

here is where things are going wrong:

Device device = new Device();
device.Url = "http:192:99:192:99:1890";  //the IP of the device

// Set the proxy to nothing so the Web Client talks directly to the Web Service
// without going through a proxy server. 
device.Proxy = new WebProxy();
                        
// get context & manufacture a license key
device.RequestHeaderValue = new RequestHeader();

device.RequestHeaderValue.LicenseKey = GetGCConnectionContext();

I read that setting the webservice KeepAlive to false would fix the issue, but I dont have direct contact with the webservice object, its burried in the Device class - which I have no controll over.

The Device object is in the "client.cs" generated code, it looks like this:

public partial class Device : System.Web.Services.Protocols.SoapHttpClientProtocol {

	//methods look like this:
	/// <remarks/>
	
	[System.Web.Services.Protocols.SoapHeaderAttribute("RequestHeaderValue")]
	
	[System.Web.Services.Protocols.SoapDocumentMethodAttribute("urn:#ChallengeLicense", Use=System.Web.Services.Description.SoapBindingUse.Literal, ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Bare)]

	[return: System.Xml.Serialization.XmlElementAttribute("ChallengeLicenseResponse", Namespace="http://website")]
	 
	 public RequestLicenseResponse ChallengeLicense([System.Xml.Serialization.XmlElementAttribute(Namespace="http://website")] ChallengeLicenseRequest ChallengeLicenseRequest) {
		object[] results = this.Invoke("ChallengeLicense", new object[] {
				ChallengeLicenseRequest});
		return ((RequestLicenseResponse)(results[0]));
	}
}

I read here that I should try to add this to the generated code:

protected override WebRequest GetWebRequest(Uri uri)
        {
            HttpWebRequest webRequest = (HttpWebRequest) base.GetWebRequest(uri);

            webRequest.KeepAlive = false;
            webRequest.ProtocolVersion=HttpVersion.Version10;
            return webRequest;
        }

but this causes the all my calls to the Device object to throw 15: license key is not valid exceptions.

I really have no idea how to go about fixing this, andy why on earth it wouldn't work on a different computer. I would appreciate any help

Edited 6 Years Ago by hanvyj: n/a

oh, and inbetween the "working" calls, and the "not workign" calls the Device object is destroyed, the COM object that holds the device object is declared null (the COM is not Couninitialized/Coinitialzed again)

It might be that the network accesses the internet through a proxy

This article has been dead for over six months. Start a new discussion instead.