简体   繁体   English

调试C#Web服务客户端

[英]Debug C# webservice client

I ran into a strange problem using a C# webservice client to call a ASP.NET 2.0 webservice. 使用C#Web服务客户端调用ASP.NET 2.0 Web服务时遇到一个奇怪的问题。 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. 该服务是一个简单的产品搜索,并返回与搜索词匹配的产品数组-请参阅下面的WSDL文件的相关部分。
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. 我的C#客户端是通过在VS2010(非WCF)中添加Web引用而简单生成的,为了进行比较,我使用的是Axis 1.4 Java客户端。
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. 在C#和Java客户端中使用相同的搜索参数,调用将返回50个产品,但是在C#客户端中,结果数组的长度为1,而Java客户端显示了正确的50个元素。

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 使用TCP / IP监视器比较Web服务返回的XML:XML看上去与C#和Java相同,并且包含50种产品
  • 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 使用netcat比较HTTP参数:C#默认为HTTP 1.1,而Axis 1.4使用HTTP 1.0,但是将C#客户端更改为也使用HTTP 1.0不会做任何更改
  • Try SOAP 1.2 instead of SOAP 1.1: No effect 尝试使用SOAP 1.2代替SOAP 1.1:无效
  • Try HttpGetProtocol, HttpPostProtocol instead of Soap 尝试使用HttpGetProtocol,HttpPostProtocol而不是Soap

Any suggestions are highly appreciated. 任何建议都将受到高度赞赏。


EDIT: Full WSDL and generated code (Reference.cs) can be found here: 编辑:完整的WSDL和生成的代码(Reference.cs)可以在这里找到:
http://timmay.dk/Reference.txt http://timmay.dk/Reference.txt
http://timmay.dk/Wsdl.txt http://timmay.dk/Wsdl.txt

Simplified WSDL part: 简化的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>

From the WSDL I gather that the maxOccurs is 1. So it seems that you should receive indeed only one SearchResult . 从WSDL中,我发现maxOccurs为1。因此,看来您应该只收到一个SearchResult However, that result itself should contain an object of type ArrayOfReponseProduct , which contains an unbounded amount of `ResponseProduct items. 但是,该结果本身应包含ArrayOfReponseProduct类型的对象,该对象包含无限制的`ResponseProduct项目。 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? 是键入对象还是未键入对象,在这种情况下,您可能需要先强制转换对象才能查看内容?

It turned out that the culprit was the type of the return values - Response field 原来,罪魁祸首是返回值的类型-响应字段

< s:complexType name="ResponseField">
    <s:sequence>
      <s:element minOccurs="0" maxOccurs="1" name="Name" type="s:string" />
      <s:element minOccurs="0" maxOccurs="1" name="Value">
        <s:complexType>
          <s:sequence>
            <s:element ref="s:schema" />
            <s:any />
          </s:sequence>
        </s:complexType>
      </s:element>
    </s:sequence>
  </s:complexType>

This was pr default converted to a System.Data.DataSet - changing this to a simple string solved the problem. pr默认将其转换为System.Data.DataSet-将其更改为简单字符串即可解决此问题。 It seems that the unmarshalling failed in this case. 在这种情况下,解组似乎失败了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM