如何让Axis2处理数组?

时间:2012-07-19 12:47:44

标签: java xml soap nusoap

我正在从PHP NuSoap实现中检索数据,它正在返回这样的数据:

<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">

<SOAP-ENV:Body>

<ns1:getHashCodeAllTablesResponse xmlns:ns1="urn:getSchemaForRhythms">

<return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType=":[121]">

<item xsi:type="xsd:">

<md5Hash xsi:type="xsd:string">e294967afe9834bf8477252ac0c3686e</md5Hash>

<tableName xsi:type="xsd:string">SYSCONGLOMERATES</tableName>

<isView xsi:type="xsd:string">false</isView>

<viewDefinition xsi:type="xsd:string">null</viewDefinition>

</item>

我认为这是问题:<return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType=":[121]">

当我将Axis2 soap客户端指向该服务时,我收到此错误:

org.apache.axis2.AxisFault: org.apache.axis2.databinding.ADBException: Unsupported type http://schemas.xmlsoap.org/soap/encoding/ Array

这是我正在尝试做的一个非常简单的java示例:

public static void main(String[] args) {
    // TODO code application logic here
    try{
        GetSchemaForRhythmsStub stub = new GetSchemaForRhythmsStub(null,"http://test.test.com/sqlSchemaService/schemaBuilder.php" );
        GetSchemaForRhythmsStub.GetHashCodeAllTablesE response2= new GetSchemaForRhythmsStub.GetHashCodeAllTablesE();
        stub.getHashCodeAllTables(response2);
    }catch(Exception ex)
    {
       System.out.println(ex.toString());

    }
}

我找不到任何与Array数据类型和Axis相关的文档。我错过了什么吗?

谢谢,

2 个答案:

答案 0 :(得分:5)

你缺少的是SOAP编码数组类型实际上是旧学校(即他们在XML Schema出现之前使用过的东西),而Axis2不喜欢它。您可以尝试将数据绑定从ADB(默认)切换到XMLBeans。如何执行此操作取决于您如何解析WSDL。以下是我发现的几个参考文献:

SOAP encoding and Axis2

Axis2's wsdl2java fails on RPC/Encoded style web services

通常,查找“soap encoded array axis2”以查找有关您正在执行的操作的信息。

答案 1 :(得分:1)

我遇到了同样的问题,生成的代码在表示数组的XMLBean上没有set方法。为了解决这个问题,我直接在生成的类上使用了XMLBean API。

以下代码片段演示了如何向生成的数组类添加元素。在我的情况下,我必须返回一个包含两个值的字符串数组。

    ArrayOfXsdString strArray = syncResponse.addNewProcessSyncReturn();

             /* set the size of the array */
    strArray.setArrayType("soapenc:string[2]");

            /* get the XMLCursor object and go to the end of the XML represented by this bean */   
    XmlCursor cur = strArray.newCursor();
    cur.toEndToken();

            /* processSyncReturn is the XML element name of the array */        
    cur.toChild("processSyncReturn");
    cur.insertElementWithText("processSyncReturn","this is array element 1");
    cur.insertElementWithText("processSyncReturn","this is array element 2");

在响应SOAP消息

中生成以下内容
<processSyncReturn soapenc:arrayType="soapenc:string[2]">
<processSyncReturn>this is array element 1</processSyncReturn>
<processSyncReturn>this is array element 2</processSyncReturn>
</processSyncReturn>

侯赛因

http://nsinfra.blogspot.in