我正在做一些性能测试,我遇到了一些令我困惑的事情,我希望有人能给我一些启发。
我正在比较HttpWebRequest和SoapHttpClientProtocol之间的性能。在我的测试中,我看到SoapHttpClientProtocol类的执行速度快了一倍。然而,我期望HttpWebRequest能有更好的表现。
感谢任何人能提供的任何见解!
相同的
下面是HttpWebRequest的代码
public string RetrieveValue()
{
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] payload = encoding.GetBytes("sIP=");
string Url = @"url/RetrieveValue";
HttpWebRequest wr = (HttpWebRequest)HttpWebRequest.Create(Url);
wr.Method = "POST";
wr.KeepAlive = false;
wr.ContentType = "application/x-www-form-urlencoded";
wr.ContentLength = payload.Length;
wr.Timeout = 30000;
HttpWebResponse webResponse;
Stream wrStream = wr.GetRequestStream();
wrStream.Write(payload, 0, payload.Length);
wrStream.Close();
webResponse = (HttpWebResponse)wr.GetResponse();
Stream baseStream = webResponse.GetResponseStream();
string result = null;
using (StreamReader sr = new StreamReader(baseStream))
result = sr.ReadToEnd();
return result;
}下面是SoapHttpClientProtocol的代码
WebServiceBinding(Name = "Soap", Namespace = "http://namespace.com/")]
public class MyRetriever : SoapHttpClientProtocol
{
[SoapDocumentMethod("http://url.com/Retrieve", RequestNamespace = "http://url.com/", ResponseNamespace = "http://url.com/", Use = SoapBindingUse.Literal, ParameterStyle = SoapParameterStyle.Wrapped)]
public string RetrieveValue(string sVal)
{
return (string)base.Invoke("RetrieveValue",
new object[] { sVal })[0];
}
}发布于 2009-11-05 01:46:18
您如何调用这两个测试?RetrieveValue每次都会建立一个新的连接,如果您使用的是测试soap客户端的单个实例,并且每次都调用GetNewSessionKey,那么您可能不会产生相同的开销。
https://stackoverflow.com/questions/1675417
复制相似问题