c#将soap响应对象转换为xml

时间:2015-04-11 07:44:35

标签: soap

我有一个响应对象,来自wsdl:

myResponse oResponse = oClient.getResponse(cmyCf,“”,cNart,“4.02”);

如何将 oResponse 转换为Xml字符串? 响应没有CDA实例! 问候。

1 个答案:

答案 0 :(得分:0)

我的自我解决方案:

        public static string ObjectToSOAP(object Object)
        {
           try
           {
            using (MemoryStream Stream = new MemoryStream())
            {
                System.Runtime.Serialization.Formatters.Soap.SoapFormatter Serializer =
                    new System.Runtime.Serialization.Formatters.Soap.SoapFormatter();
                Serializer.Serialize(Stream, Object);
                Stream.Flush();
                return UTF8Encoding.UTF8.GetString(Stream.GetBuffer(), 0, (int)Stream.Position);
            }
        }
        catch { throw; }
    }

对于有同样问题的人。