C# WCF传递XML文档
我创建了WCF服务。我有两个文件: IHelloService.cs文件:C# WCF传递XML文档,c#,wcf,C#,Wcf,我创建了WCF服务。我有两个文件: IHelloService.cs文件: namespace HelloService { [ServiceContract] public interface IHelloService { [OperationContract] void GetXmlDocumentt(XmlDocument Doc); } } HelloService.cs文件: public
namespace HelloService
{
[ServiceContract]
public interface IHelloService
{
[OperationContract]
void GetXmlDocumentt(XmlDocument Doc);
}
}
HelloService.cs文件:
public void GetXmlDocumentt(XmlDocument Doc)
{
// return Doc;
}
我选择了“添加服务引用”,并在我的客户端应用程序中添加我的服务引用和类型:
XmlDocument xmlDoc = new XmlDocument();
//.. load xml from file
HelloService.HelloServiceClient client = new HelloService.HelloServiceClient("BasicHttpBinding_IHelloService");
client.GetXmlDocumentt(xmlDoc); // I get error in this line
我不知道为什么?因为当我在接口中将类型从XmlDocument回复到string时,我将在这一行中传递client.GetXmlDocumentt(“任何数据”)
string,一切正常
您能解释一下为什么字符串类型可以工作,但XmlDocument
不能工作吗
如何将代码更改为XmlDocument
正常工作
谢谢
XmlDocument
没有实现DataContractSerializer使用的IXmlSerializable
接口。你有3种方法:
Xml.Linq
处理Xml并在XDocument
类中发送数据如果我们知道错误消息所说的内容,而不仅仅是“它不工作/It错误”等等,这会有所帮助。错误消息:与“MvcLogowanie.HelloService.HelloService Client.GetXmlDocumentt(object[])”匹配的最佳重载方法有一些无效参数参数参数1:无法从“System.Xml.XmlDocument”转换为“object[]”