0

我有一个需要使用 wsdl 合同与之通信的 java 网络服务器。我没有构建服务器,也无权访问它的源代码。我构建了 ac# 应用程序,并使用 Visual Studio“添加服务引用”将服务引用添加到 wsdl 合同。我粘贴了我感兴趣的 wsdl 部分:

<wsdl:operation name="SOAPRequestItemHead" parameterOrder="SessionID searchitems">
  <wsdl:input message="impl:SOAPRequestItemHeadRequest" name="SOAPRequestItemHeadRequest"/>
  <wsdl:output message="impl:SOAPRequestItemHeadResponse" name="SOAPRequestItemHeadResponse"/>
</wsdl:operation>
<wsdl:operation name="SOAPRequestItemHead">
  <wsdlsoap:operation soapAction=""/>
  <wsdl:input name="SOAPRequestItemHeadRequest">
    <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://wrapper.soap.aplusb.com" use="encoded"/>
  </wsdl:input>
  <wsdl:output name="SOAPRequestItemHeadResponse">
    <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://192.168.200.26:8888/tcdnc/services/fsw" use="encoded"/>
  </wsdl:output>
</wsdl:operation>
<wsdl:message name="SOAPRequestItemHeadResponse">
  <wsdl:part name="SOAPRequestItemHeadReturn" type="tns2:SOAPItemRevisionHeadResult"/>
</wsdl:message>
<complexType name="SOAPItemRevisionHeadResult">
  <sequence>
    <element maxOccurs="1" minOccurs="0" name="comment" nillable="true" type="xsd:string"/>
    <element name="searchComplete" type="xsd:boolean"/>
    <element maxOccurs="unbounded" minOccurs="0" name="search" type="tns2:StringMap"/>
    <element maxOccurs="unbounded" minOccurs="0" name="resultList" type="tns2:SOAPItemRevisionHead"/>
  </sequence>
</complexType>

请注意,resultListandsearch是数组。如果我调用此方法,这是原始响应,使用 SOAP 工具获取:

<SOAPRequestItemHeadReturn xmlns:ns2="fsw" xsi:type="ns2:SOAPItemRevisionHeadResult">
  <comment xsi:type="xsd:string" xsi:nil="true"/>
  <searchComplete xsi:type="xsd:boolean">true</searchComplete>
  <resultList xsi:type="ns2:SOAPItemRevisionHead">
    <search xsi:type="ns2:StringMap">
      <stringKey xsi:type="xsd:string">ItemRevision.ItemID</stringKey>
      <stringValue xsi:type="xsd:string">cam_english_template</stringValue>
    </search>
    <search xsi:type="ns2:StringMap">
      <stringKey xsi:type="xsd:string">ItemRevision.Revision</stringKey>
      <stringValue xsi:type="xsd:string">A</stringValue>
    </search>
    <dummy xsi:type="xsd:string" xsi:nil="true"/>
  </resultList>
  <resultList xsi:type="ns2:SOAPItemRevisionHead">
...

如您所见,resultList实际上search是数组。但是当我从我的 c# 客户端调用该方法时,我得到了这个错误:

反序列化操作“SOAPRequestItemHead”的回复消息正文时出错。

内部异常:XML 文档中存在错误 (1, 815)。

内部异常:无法将 StringMap 类型的对象分配给 StringMap[] 类型的对象

如果我转到Reference.cs自动生成的那个,并且我手动将两个应该是数组的属性的类型更改StringMap[]StringMap不会抛出错误,但是当然我只能在我的数组中获取第一项程序。我希望我很清楚,即使这是一个很长的问题。

更新:我知道这是使用 Axis 1.4 的问题,它使用 rcp/encoded 而不是 document/literal,所以可以用这些术语重新表述问题:“.NET 可以正确处理 rcp/encoded 吗?”

4

3 回答 3

0

检查 VS 生成的数据合约。它们还应包含“resultList”的特定类型,并用CollectionDataContract属性装饰。我还将检查名称空间和名称是否在DataContract属性上精确设置。

编辑:关于 RPC 风格的 Web 服务,您可以在这些链接上找到一些解决方法:http: //social.msdn.microsoft.com/Forums/vstudio/en-US/51babae5-26e5-4405-b03c-4301710854c0/why-does- add-service-reference-fail-to-build-a-proper-reference-for-dfa?forum=wcf http://social.msdn.microsoft.com/Forums/vstudio/en-US/07edda1a-d0d5-4920 -b2fb-a25c803269d6/trouble-with-sumption-a-java-rpc-web-service-using-net-client?forum=wcf

于 2013-10-21T15:07:10.910 回答
0

据我所知,SOAPItemRevisionHeadResultWSDL 中的类型定义有问题。

<complexType name="SOAPItemRevisionHeadResult">
  <sequence>
    <element maxOccurs="1" minOccurs="0" name="comment" nillable="true" type="xsd:string"/>
    <element name="searchComplete" type="xsd:boolean"/>
    <element maxOccurs="unbounded" minOccurs="0" name="search" type="tns2:StringMap"/>
    <element maxOccurs="unbounded" minOccurs="0" name="resultList" type="tns2:SOAPItemRevisionHead"/>
  </sequence>
</complexType>

具有此定义的类型映射到:

Public class SOAPItemRevisionHeadResult{

    public string comment;
    public boolean searchComplete;
    public Stringmap[] search;  
    public SOAPItemRevisionHead[] resultList;
}

Public class StringMap{
//can't see definition of this type in your part of WSDL posted but doesn't matter.
//guesed definition by looking at the response
    public string StringKey;
    public string StrigValue;
//end of guesed definition
}

Public class SOAPItemRevisionHead{
  //can't see definition of this type in your part of WSDL posted but doesn't matter.
  //guesed definition by looking at the response
    public StringMap[] search;
  //end of guesed definition
}

似乎不好的嵌套类,WSDL但在Raw Response你发布的我可以看到正确的嵌套:

Public class SOAPItemRevisionHeadResult{

    public string comment;
    public boolean searchComplete;
    public resultList as SOAPItemRevisionHead[]; 
}

Public class SOAPItemRevisionHead{

    public StringMap[] search;
}

Public class StringMap{

    public string StringKey;
    public string StrigValue;
}
于 2013-10-24T12:39:10.213 回答
0

如果可能,您可能想考虑替代该编码,请参阅:
http ://security-world.blogspot.dk/2005/07/nt-aspnet-rcpencoded-web-service-dos.html

我相信您正在寻找的答案在这篇文章中:
http ://social.msdn.microsoft.com/Forums/vstudio/en-US/51babae5-26e5-4405-b03c-4301710854c0/why-does-add- service-reference-fail-to-build-a-proper-reference-for-dfa?forum=wcf

更正了上面的链接,不知道为什么放错了

于 2013-10-24T12:25:36.947 回答