如何反序列化WCF响应 [英] How can a Deserialize a WCF response
本文介绍了如何反序列化WCF响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为了进行测试,我有一个应用程序正在向WCF服务发送请求,就像这样
For testing I have an app that is sending a request to a WCF service like this
Uri uri = host.StartsWith("http:")
? new Uri(host)
: new UriBuilder("http://", host, 80, "servername").Uri;
var request = WebRequest.Create(uri);
request.ContentType = "application/soap+xml; charset=utf-8";
request.Method = "POST";
using (var stream = request.GetRequestStream())
{
stream.Write(Encoding.UTF8.GetBytes(xml), 0, xml.Length);
}
#if true
try
{
using (var response = request.GetResponse() as HttpWebResponse)
using (var responseStream = response.GetResponseStream())
using (var sr = new StreamReader(responseStream))
{
return sr.ReadToEnd();
}
}
catch (Exception ex)
{
return String.Format("<exception>{0}<stacktrace>{1}</stacktrace></exception>", ex.Message, ex.StackTrace);
}
我该如何接受该函数返回的响应并将其反序列化为对象?
how can I take the response this function returns and deserialize it into an object ?
推荐答案
我建议按[优先顺序]中的一个建议:
a)从MEX生成代理
b)在客户端的WCF服务中包括数据和服务合同接口.
否则,您将陷入一个通常不必要的痛苦世界.有什么原因不能执行(a)或(b)?
I''d suggest either [in order of preference]:
a) Generating a proxy from the MEX
b) Including the Data and Service Contract interfaces in from the WCF service in the client.
Otherwise you are in for a world of usually needless pain. Is there any reason why you cannot do (a) or (b)?
这篇关于如何反序列化WCF响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文