内部异常的属性设置?
我写一个WCF Web服务的单元测试。我故意发送一个无效的请求给服务器,抛出一个 WebExceptionFault<串GT;
。在单元测试,这被逮住的异常是 EndpointNotFoundException
与在引发WebException
>的InnerException 属性。我想验证响应的身体,我认为应该在那里的字符串相匹配。
I am writing a unit test for a WCF web service. I am deliberately sending an invalid request to the server which throws a WebExceptionFault<string>
. In the unit test, the Exception that gets caught is an EndpointNotFoundException
with the standard WebException
in the InnerException
property. I want to verify the body of the response matches the string that I think should be there.
我来翻过一个问题,但是,由于的响应
属性引发WebException
(其为 System.Net.SyncMemoryStream
)被设置,并且不能被读取
I am coming accross a problem, however, as the Response
property of the WebException
(which is a System.Net.SyncMemoryStream
) is Disposed and can not be read.
我的代码:
Clubs actual;
try
{
//"201" is an invalid argument for the first parameter
actual = new Clubs(channel.GetClubs("201", "123"));
}
catch (EndpointNotFoundException e)
{
WebException w = e.InnerException as WebException;
Assert.IsNotNull(w);
HttpWebResponse resp = w.Response as HttpWebResponse;
Assert.IsNotNull(resp);
Assert.AreEqual(resp.StatusCode, HttpStatusCode.NotFound);
//Next line throws an ArgumentException saying Stream not readable
//Investigation shows it has been disposed
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
Assert.AreEqual(sr.ReadToEnd(), "League not allowed for selected club");
}
这是正常的的InnerException的属性被设置?有没有解决这个办法吗?
Is it normal that the properties of the InnerException are disposed? Is there any way around this?
似乎是一个例外的序列化问题。您可能需要捕获错误的服务器和自定义生成一个错误消息
Seems a Exception serialization issue. You might have to trap the error on server and custom build a error message