调试 C# Web 服务客户端
我在使用 C# Web 服务客户端调用 ASP.NET 2.0 Web 服务时遇到了一个奇怪的问题。 该服务是一个简单的产品搜索,并返回与搜索词匹配的一系列产品 - 请参阅下面 WSDL 文件的相关部分。
我的 C# 客户端是通过在 VS2010(非 WCF)中添加 Web 引用简单生成的,为了进行比较,我使用的是 Axis 1.4 Java 客户端。
在 C# 和 Java 客户端中使用相同的搜索参数,调用返回 50 个产品,但在 C# 客户端中,结果数组的长度为 1,而 Java 客户端显示正确的 50 个元素。
我正在寻找如何定位问题的建议 - 我已尝试以下操作:
- 使用 TCP/IP 监视器比较 Web 服务返回的 XML:XML 看起来与 C# 与 Java 相同,并且包含 50 个产品
- 使用 netcat 比较 HTTP 参数:C# 默认为 HTTP 1.1,而 Axis 1.4 使用 HTTP 1.0,但将 C# 客户端更改为使用 HTTP 1.0 也不会改变任何内容
- 尝试 SOAP 1.2 而不是 SOAP 1.1:没有效果
- 尝试 HttpGetProtocol、HttpPostProtocol 而不是 Soap
非常感谢任何建议。
编辑:完整的 WSDL 和生成的代码 (Reference.cs) 可以在这里找到:
http://timmay.dk/Reference.txt
http://timmay.dk/Wsdl.txt
简化的 WSDL 部分:
<s:element name="Search">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="SearchTerm" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="StartFrom" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="NumberToBeReturned" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="SearchResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="SearchResult" type="tns:SearchResult" />
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="SearchResult">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Products" type="tns:ArrayOfResponseProduct" />
</s:sequence>
</s:complexType>
<s:complexType name="ArrayOfResponseProduct">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="ResponseProduct" nillable="true" type="tns:ResponseProduct" />
</s:sequence>
</s:complexType>
<s:complexType name="ResponseProduct">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Fields" type="tns:ArrayOfResponseField" />
</s:sequence>
<s:attribute name="id" type="s:string" />
</s:complexType>
I ran into a strange problem using a C# webservice client to call a ASP.NET 2.0 webservice.
The service is a simple product search and returns an array of products matching a search term - see the relevant part of the WSDL file below.
My C# client is simply generated by adding a web reference in VS2010 (non-WCF) and for comparison I'm using an Axis 1.4 Java client.
Using the same search paramaters in both the C# and the Java client the call returns 50 products but in the C# client the result array has length 1 while the Java client shows up the correct 50 elements.
I am looking for suggestions how to locate the problem - I've tried the following:
- Compare the XML returned by the webservice using a TCP/IP monitor: The XML looks identical C# vs. Java and contains the 50 products
- Compare HTTP parameters using netcat: C# defaults to HTTP 1.1 while Axis 1.4 uses HTTP 1.0, but changing the C# client to use HTTP 1.0 as well does no change anything
- Try SOAP 1.2 instead of SOAP 1.1: No effect
- Try HttpGetProtocol, HttpPostProtocol instead of Soap
Any suggestions are highly appreciated.
EDIT: Full WSDL and generated code (Reference.cs) can be found here:
http://timmay.dk/Reference.txt
http://timmay.dk/Wsdl.txt
Simplified WSDL part:
<s:element name="Search">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="SearchTerm" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="StartFrom" type="s:string" />
<s:element minOccurs="0" maxOccurs="1" name="NumberToBeReturned" type="s:string" />
</s:sequence>
</s:complexType>
</s:element>
<s:element name="SearchResponse">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="SearchResult" type="tns:SearchResult" />
</s:sequence>
</s:complexType>
</s:element>
<s:complexType name="SearchResult">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Products" type="tns:ArrayOfResponseProduct" />
</s:sequence>
</s:complexType>
<s:complexType name="ArrayOfResponseProduct">
<s:sequence>
<s:element minOccurs="0" maxOccurs="unbounded" name="ResponseProduct" nillable="true" type="tns:ResponseProduct" />
</s:sequence>
</s:complexType>
<s:complexType name="ResponseProduct">
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="Fields" type="tns:ArrayOfResponseField" />
</s:sequence>
<s:attribute name="id" type="s:string" />
</s:complexType>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
从 WSDL 中,我了解到
maxOccurs
为 1。因此看来您实际上应该只收到一个SearchResult
。然而,该结果本身应该包含一个ArrayOfReponseProduct
类型的对象,其中包含无限数量的“ResponseProduct”项。也许你看的不够深入?您是否尝试过使用变量检查器(本地、自动、立即等)检查调试器内部?该对象是类型化的还是非类型化的,在这种情况下您可能需要先转换它才能查看内容?
From the WSDL I gather that the
maxOccurs
is 1. So it seems that you should receive indeed only oneSearchResult
. However, that result itself should contain an object of typeArrayOfReponseProduct
, which contains an unbounded amount of `ResponseProduct items. Maybe you are not looking deep enough?Have you tried to check inside the debugger with the variable inspectors (Local, Auto, Immediate etc)? Is the object typed, or untyped, in which case you may need to cast it first to see the contents?
事实证明,罪魁祸首是返回值的类型 - 响应字段
默认转换为 System.Data.DataSet - 将其更改为简单的字符串解决了问题。在这种情况下,解组似乎失败了。
It turned out that the culprit was the type of the return values - Response field
This was pr default converted to a System.Data.DataSet - changing this to a simple string solved the problem. It seems that the unmarshalling failed in this case.