c#执行soap客户端方法错误

本文关键字:方法 错误 客户端 soap 执行 | 更新日期: 2023-09-27 18:16:13

我使用visual studio 2010 Pro从wsdl文件创建客户端,创建新项目,右键单击Reference,选择"Add Service Reference…",然后写下web服务的地址,点击完成。在Visual Studio生成部分类之后,调用有两个参数的方法:

CompanyClient client = new CompanyClient();
log[] logs = client.GetLogs(new System.DateTime(2000, 11, 22), new System.DateTime(2011, 11, 22));

则有例外:

SystemInvalidException: There was an error reflecting 'arg0'.

内部例外:

System.InvalidOperationException: The top XML element 'arg0' from namespace '' references distinct types System.DateTime and System.Int32. Use XML attributes to specify another XML name or namespace for the element or types.

我用scala写了soapserver,用SoapUI测试了它,一切正常,但是在开发客户端时出现了这样的问题。

c#执行soap客户端方法错误

问题是,您可能有两个arg0类(或其变体)来自两个不同的名称空间(在代码端),但在xml端序列化为相同的根名称+名称空间。SOAP序列化器不喜欢这样,因为它无法确定是否将给定类型反序列化为ns1。Arg0或ns2。当它看到xml.

这里讨论了问题和解决方案:http://social.msdn.microsoft.com/Forums/ar/asmxandxml/thread/e3405d68-9d48-4600-8fa0-1587aa380c47

欢呼,Anash