我正在尝试使用 C# 使用 wsdl 网络服务 (java)。我添加了服务引用并实现了 webmethod 调用,但它返回以下错误: 格式化程序在尝试反序列化消息时抛出异常:
There was an error while trying to deserialize parameter http://services.company.companyname.com.br:methodNameResponse. The InnerException message was 'Error in line 1 position 456. 'EndElement' 'methodNameReturn' from namespace 'http://services.company.companyname.com.br' is not expected. Expecting element 'idSomething'.'. Please see InnerException for more details.
我已经尝试了很多东西,比如限制大小、在主机文件上添加 ip 等,但都没有成功。有人有想法吗?
代码是:
var ws = new webService(); //invoked using the service reference
var return = ws.methodName("x", "CAY", "5454545", "XXXX", "xxx", "09/07", "A", 1,
"23/04/2013", "23/04/2013", "15:00", "17:00");
ws.methodName 返回错误。
我已经尝试使用请求和响应对象并得到了同样的错误。
我还使用网络引用进行了测试。我有一种方法它不会返回错误,但我需要更改引用文件,在调用的方法上方注释以下行:
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://dto.services.company.trielo.com.br")]
我正在发布 wsdl:http://177.140.208.200:8998/mdc4web/services/VisitantesSASweb?wsdl
请您参考如下方法:
我发现 Visual Studio 生成的代理类和服务 WSDL 之间可能存在两个问题
查看代理生成的文件:
第一个错误是 RetVisSRV 类中 XmlTypeAttribute 属性的命名空间参数
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://dto.services.mdc4web.trielo.com.br")]
你需要删除“dto”。
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://services.mdc4web.trielo.com.br")]
第二点是“lst”数组声明的XmlArrayItemAttribute处的elementName参数。
[System.Xml.Serialization.XmlArrayItemAttribute("item", Namespace="http://services.mdc4web.trielo.com.br", IsNullable=false)]
正确为“lst”
[System.Xml.Serialization.XmlArrayItemAttribute("lst", Namespace="http://services.mdc4web.trielo.com.br", IsNullable=false)]
经过这些更改后应该可以正常工作。
这个命名空间问题是 AXIS 和 .NET 客户端之间的一个已知问题,但我不知道为什么还没有解决
参见 https://issues.apache.org/jira/browse/AXIS-2449
希望对你有帮助
