我遇到了很多人都遇到过的问题,但是在线提供的所有解决方案都特定于他们的场景。我已经尝试了可用的建议,但我尝试过的仍然没有运气:
1.) req.KeepAlive = false;
2.) req.ProtocolVersion = HttpVersion.Version10; (this solved a different exception that I was getting)
我有两种方法将 XML 字符串传递给服务器并返回响应,这两种方法是:
public string userDeviceQuery(string userID)
{
string query = "xml=<query>";
query += "<appInfo>";
query += "<appID>" + appID + "</appID>";
query += "<appCertificate>" + appCertificate + "</appCertificate>";
query += "</appInfo>";
query += "<userDevicesQuery>";
query += "<userID>";
query += userID;
query += "</userID>";
query += "</userDevicesQuery>";
query += "</query>";
using (Stream str = req.GetRequestStream())
{
str.Write(System.Text.Encoding.ASCII.GetBytes(query), 0, query.Length);
}
WebResponse res = req.GetResponse();
string stringResponse;
using (StreamReader reader = new StreamReader(res.GetResponseStream()))
{
stringResponse = reader.ReadToEnd();
}
string result = parseDeviceQueryRes(stringResponse);
return result;
}
和
public void logoutOfEM(string deviceName)
{
string lgRequest = "xml=<request>";
lgRequest += "<appInfo>";
lgRequest += "<appID>" + appID + "</appID>";
lgRequest += "<appCertificate>" + appCertificate + "</appCertificate>";
lgRequest += "</appInfo>";
lgRequest += "<logout>";
lgRequest += "<deviceName>";
lgRequest += deviceName;
lgRequest += "</deviceName>";
lgRequest += "</logout>";
lgRequest += "</request>";
using (Stream str = req.GetRequestStream())
{
str.Write(System.Text.Encoding.ASCII.GetBytes(lgRequest), 0, lgRequest.Length);
}
WebResponse res = req.GetResponse();
using (StreamReader reader = new StreamReader(res.GetResponseStream()))
{
stringResponse = reader.ReadToEnd();
}
string stringResponse = reader.ReadToEnd();
}
它们都是名为 EMAPI 的类的一部分。我可以单独使用这两种方法,但是如果尝试将它们与表示 EMAPI 的相同对象背靠背使用,我会得到上述异常。我不确定是什么导致连接关闭,如果可能的话,我希望能够保持打开并使用解构器关闭它。
对于那些好奇此代码处理 Cisco Extension Mobility API 的人,第一种方法查询服务器以获取您登录的设备,第二种方法将用户从该设备中注销。
谢谢您的帮助。