我有一个java网络服务器,我需要使用wsdl合同进行通信。我没有构建服务器,我无法访问其源代码。我构建了一个c#应用程序,并使用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>
请注意,resultList
和search
是数组。如果我调用此方法,这里是使用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?”
答案 0 :(得分: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-consuming-a-java-rpc-web-service-using-net-client?forum=wcf
答案 1 :(得分:0)
如果可能,您可能想考虑替代该编码,请参阅:
http://security-world.blogspot.dk/2005/07/nt-aspnet-rcpencoded-web-service-dos.html
更正上面的链接,不知道为什么错误的人进去了
答案 2 :(得分:0)
据我所知,WSDL中的SOAPItemRevisionHeadResult
类型定义出了问题。
<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;
}