同事已经在Tomcat 6服务器上的Apache-SOAP运行时上运行了Java Web服务,但只使用Eclipse的内置工具和SoapUI对其进行了测试。此服务的输出是一个对象数组,每个对象由五个字符串字段组成。我需要编写.NET客户端来使用此服务,并使用Visual Studio 2005将WSDL作为Web引用导入。该方法成功执行,并使用正确数量的对象填充数组,但每个对象的字段显示为null。
我使用Fiddler验证返回给客户端的XML是否正确,但.NET客户端类似乎无法反序列化它。有什么想法吗?
更多数据:
- WSDL定义为文档/文字
- 返回XML不包含“multiref”部分,我已经看到了编写自定义soap属性的建议
- 返回XML似乎为返回中的每个对象定义了一个新的但相同的命名空间。客户端是否只是不了解不同的命名空间名称,即使每个名称解析为相同的类型(在WSDL中指定)?
- 请求XML似乎指定了UTF-16而不是UTF-8。单独改变这似乎没有帮助
- 使用第三方工具(.NET WebService Studio)返回服务上其他方法的有效响应,但异常“System.Xml.XmlException:根级别的数据无效。第1行,位置1”。对于我正在研究的方法。这是一个单独的问题吗? (我读过它可能是由Transport-Encoding引起的:chunked)
我希望这很简单,这样我就不必在发布之前清理(长)WSDL的证据。与此同时,这是请求和响应XML。
请求:
<?xml version="1.0" encoding="utf-16"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<getPrinterList xmlns="http://service.project.team.dept.company.com" />
</soap:Body>
</soap:Envelope>
回应:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<getPrinterListResponse xmlns="http://tempuri.org/com.company.team.dept.project.service.projectService">
<ns1:getPrinterListReturn xmlns:ns1="http://service.project.dept.team.company.com">
<ns1:printerType>type1</ns1:printerType>
<ns1:queueName>queue1</ns1:queueName>
<ns1:description>desc1</ns1:description>
<ns1:hostName>host1</ns1:hostName>
<ns1:hostPort>port1</ns1:hostPort>
</ns1:getPrinterListReturn>
<ns2:getPrinterListReturn xmlns:ns2="http://service.project.dept.team.company.com">
<ns2:printerType>type2</ns2:printerType>
<ns2:queueName>queue2</ns2:queueName>
<ns2:description>desc2</ns2:description>
<ns2:hostName>host2</ns2:hostName>
<ns2:hostPort>port2</ns2:hostPort>
</ns2:getPrinterListReturn>
<ns3:getPrinterListReturn xmlns:ns3="http://service.project.dept.team.company.com">
<ns3:printerType>type3</ns3:printerType>
<ns3:queueName>queue3</ns3:queueName>
<ns3:description>desc3</ns3:description>
<ns3:hostName>host3</ns3:hostName>
<ns3:hostPort>port3</ns3:hostPort>
</ns3:getPrinterListReturn>
<ns4:getPrinterListReturn xmlns:ns4="http://service.project.dept.team.company.com">
<ns4:printerType>type4</ns4:printerType>
<ns4:queueName>queue4</ns4:queueName>
<ns4:description>desc4</ns4:description>
<ns4:hostName>host4</ns4:hostName>
<ns4:hostPort>port4</ns4:hostPort>
</ns4:getPrinterListReturn>
<ns5:getPrinterListReturn xmlns:ns5="http://service.project.dept.team.company.com">
<ns5:printerType>type5</ns5:printerType>
<ns5:queueName>queue5</ns5:queueName>
<ns5:description>desc5</ns5:description>
<ns5:hostName>host5</ns5:hostName>
<ns5:hostPort>port5</ns5:hostPort>
</ns5:getPrinterListReturn>
</getPrinterListResponse>
</soapenv:Body>
</soapenv:Envelope>
同样,响应被正确地带入应用程序并被转换为正确类型和长度的数组,但其中的每个文本项(“type1”,“port1”等)都将丢失。如果匿名化上述XML会引入错误,我真诚地道歉。
答案 0 :(得分:0)
我之前在Tomcat中将.Net客户端连接到Apache Axis时遇到了一个奇怪的现象。您是否将您的webreference指向* .wsdl文件?尝试将Web引用指向Axis打印出来的wsdl定义。转到/axis/index.jsp&gt;列表&gt;选择服务并单击WSDL。将该URL用于您的webreference对象
它对生成的Web引用代码产生了很大的影响,并解决了XML数据上的编码问题(RPC与文字等)