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

时间:2011-12-01 05:15:15

标签: c# xml soap

我使用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对其进行了测试,一切正常,但在开发客户端时出现了这样的问题。

1 个答案:

答案 0 :(得分:2)

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

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

干杯, Anash