关于SoapFormatter反序列化的问题
SoapFormatter在普通的应用程序可以运行的很好,
但是我把他放到WebService中去使用的是后总是报告错误.
请高手指教.!
以下是我在普通应用程序中使用的情况:
using System;
using System.Net;
using System.IO;
using System.Text;
using System.Web;
using System.Xml;
using System.Xml.Xsl;
using System.Runtime.Serialization.Formatters.Soap;
using System.Runtime.Serialization.Formatters.Binary;
class ClientPOST {
public static void Main(string[] args) {
SoapFormatter formatter = new SoapFormatter();
FileStream mstream = new FileStream(@"H:\XSchool\MSWeb\bin\tt.xml", FileMode.Open);
Test rinfo = (Test)formatter.Deserialize(mstream);
Console.WriteLine(rinfo.Name);
}
}
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.rookiesoft.com/webservices/")]
[Serializable()]
public class Test
{
public string Name;
public Test()
{
this.Name = "";
}
public Test(string name)
{
this.Name = name;
}
}
tt.xml中内容如下:
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:clr="http://schemas.microsoft.com/soap/encoding/clr/1.0" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<a1:Test id="ref-1" xmlns:a1="http://schemas.microsoft.com/clr/assem/tt%2C%20Version%3D0.0.0.0%2C%20Culture%3Dneutral%2C%20PublicKeyToken%3Dnull">
<Name id="ref-3">Liaoyuan</Name>
</a1:Test>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
放到WebService中时,
SoapFormatter formatter = new SoapFormatter();
FileStream fstream = new FileStream(@"H:\XSchool\MSWeb\bin\tt.xml", FileMode.Open);
Test rinfo = (Test)formatter.Deserialize(fstream);
((ResponseInfo)objReturn).ErrorMessage += rinfo.Name;
fstream.Close();
结果在Test rinfo = (Test)formatter.Deserialize(fstream);
((ResponseInfo)这里出错,
不知道为什么, 如果我转换的是String一类的简单类型的话,没问题.