Skip to content

Commit

Permalink
Merge pull request kaltura#350 from kaltura/IX-9.4.0-csharp-free-webr…
Browse files Browse the repository at this point in the history
…esponse

make sure the WebResponse object is disposed
  • Loading branch information
erankor committed Oct 20, 2013
2 parents c6b4c2f + f0ff296 commit 0ee08ae
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions generator/sources/csharp/KalturaClient/KalturaClientBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,38 +202,40 @@ public XmlElement DoQueue()
}

// get the response
WebResponse response = request.GetResponse();
Encoding enc = System.Text.Encoding.UTF8;
StreamReader responseStream = new StreamReader(response.GetResponseStream(), enc);
string responseString = responseStream.ReadToEnd();

this._ResponseHeaders = response.Headers;
string serverName = null;
string serverSession = null;
for(int i = 0; i < this._ResponseHeaders.Count; ++i)
{
if (this._ResponseHeaders.Keys[i] == "X-Me")
serverName = this._ResponseHeaders[i];
if (this._ResponseHeaders.Keys[i] == "X-Kaltura-Session")
serverSession = this._ResponseHeaders[i];
}
if (serverName != null || serverSession != null)
this.Log("server: [" + serverName + "], session: [" + serverSession + "]");

this.Log("result (serialized): " + responseString);
using (WebResponse response = request.GetResponse())
{
Encoding enc = System.Text.Encoding.UTF8;
StreamReader responseStream = new StreamReader(response.GetResponseStream(), enc);
string responseString = responseStream.ReadToEnd();

this._ResponseHeaders = response.Headers;
string serverName = null;
string serverSession = null;
for (int i = 0; i < this._ResponseHeaders.Count; ++i)
{
if (this._ResponseHeaders.Keys[i] == "X-Me")
serverName = this._ResponseHeaders[i];
if (this._ResponseHeaders.Keys[i] == "X-Kaltura-Session")
serverSession = this._ResponseHeaders[i];
}
if (serverName != null || serverSession != null)
this.Log("server: [" + serverName + "], session: [" + serverSession + "]");

DateTime endTime = DateTime.Now;
this.Log("result (serialized): " + responseString);

this.Log("execution time for [" + url + "]: [" + (endTime - startTime).ToString() + "]");
DateTime endTime = DateTime.Now;

XmlDocument xml = new XmlDocument();
xml.LoadXml(responseString);
this.Log("execution time for [" + url + "]: [" + (endTime - startTime).ToString() + "]");

this.ValidateXmlResult(xml);
XmlElement result = xml["xml"]["result"];
this.ThrowExceptionOnAPIError(result);
XmlDocument xml = new XmlDocument();
xml.LoadXml(responseString);

return result;
this.ValidateXmlResult(xml);
XmlElement result = xml["xml"]["result"];
this.ThrowExceptionOnAPIError(result);

return result;
}
}
private void createProxy(HttpWebRequest request, KalturaConfiguration _Config)
{
Expand Down

0 comments on commit 0ee08ae

Please sign in to comment.