使用JAXRPC将字符串数组作为参数发送到Web服务方法

时间:2011-07-01 04:19:56

标签: java web-services axis jax-rpc

我在向特定wsdl中给出的Web服务方法发送字符串数组作为参数时遇到了问题。当我尝试发送一个字符串数组时,我收到以下错误。

错误:

AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode: 
faultString: org.xml.sax.SAXException: Bad types (class java.util.ArrayList > 
class usdjws65.ArrayOfString)
faultActor: 
faultNode: 
faultDetail: 
            {http://xml.apache.org/axis/}hostname:SSLSPSD001

org.xml.sax.SAXException: Bad types (class java.util.ArrayList -> class usdjws65.ArrayOfString)
at org.apache.axis.message.SOAPFaultBuilder.createFault(SOAPFaultBuilder.java:222)
at org.apache.axis.message.SOAPFaultBuilder.endElement(SOAPFaultBuilder.java:129)
at  org.apache.axis.encoding.DeserializationContext.endElement(DeserializationContext.java:1087)

编写的代码:

Call call1 = objService1.createCall(port1);
call1.setTargetEndpointAddress(targetEndPoint);
call1.addParameter("int_1", XMLType.XSD_INT, Integer.class,
                ParameterMode.IN);
        call1.addParameter("String_1", QNAME_TYPE_STRING, ParameterMode.IN);
        call1.addParameter("String_2", QNAME_TYPE_STRING_ARRAY,
                java.lang.String[].class, ParameterMode.IN);
        call1.addParameter("String_3", QNAME_TYPE_STRING_ARRAY,
                java.lang.String[].class, ParameterMode.IN);
        call1.addParameter("String_4", QNAME_TYPE_STRING, ParameterMode.IN);
        call1.addParameter("String_5", QNAME_TYPE_STRING_ARRAY,
                java.lang.String[].class, ParameterMode.IN);
        call1.addParameter("String_6", QNAME_TYPE_STRING, ParameterMode.IN);
        call1.addParameter("String_7", QNAME_TYPE_STRING, ParameterMode.IN);

        // --- Done adding PARAM's

        String[] attrVals = { "description", "test from soapUI",
                "customer", ticketHandle, "type", "I" };
        String[] attributes = { "status", "ref_num" };

        Object[] params1 = { new Integer(sid), ticketHandle, attrVals, "",
                "cr_tpl:400005", attributes, "", "" };

        String res = null;
        try {
            call1.invoke(params1);

谢谢!!!! -AJ

=============================================== ==========

更新-1

我添加了一个名为ArrayOfString的类,其中包含以下代码。     protected java.lang.String [] string;

public ArrayOfString() {
}

public ArrayOfString(java.lang.String[] string) {
    this.string = string;
}

public java.lang.String[] getString() {
    return string;
}

public void setString(java.lang.String[] string) {
    this.string = string;
}

因此做了以下,     ArrayOfString attrVals = new ArrayOfString();     attrVals.setString(new String [] {“customer”,“来自soapUI的测试”,                         “客户”,ticketHandle,“type”,“I”});

类似地,对于'ArrayOfString'类型的属性变量。

但是现在,我收到以下错误::

  

AxisFault    faultCode:{http://schemas.xmlsoap.org/soap/envelope/} Server.userException    faultSubcode:    faultString:java.io.IOException:没有为注册表中的类ArrayOfString找到序列化程序org.apache.axis.encoding.TypeMappingDelegate@ef2c60    faultActor:    faultNode:    faultDetail:       {http://xml.apache.org/axis/} stackTrace:java.io.IOException:没有为注册表中的类ArrayOfString找到序列化程序org.apache.axis.encoding.TypeMappingDelegate@ef2c60       在org.apache.axis.encoding.SerializationContext.serializeActual(SerializationContext.java:1507)       在org.apache.axis.encoding.SerializationContext.serialize(SerializationContext.java:980)       在org.apache.axis.encoding.SerializationContext.outputMultiRefs(SerializationContext.java:1055)       在org.apache.axis.message.SOAPBody.outputImpl(SOAPBody.java:145)       在org.apache.axis.message.SOAPEnvelope.outputImpl(SOAPEnvelope.java:478)       at org.apache.axis.message.MessageElement.output(MessageElement.java:1208)       在org.apache.axis.client.Call.invoke(Call.java:2757)       在org.apache.axis.client.Call.invoke(Call.java:2443)       在org.apache.axis.client.Call.invoke(Call.java:2366)       在org.apache.axis.client.Call.invoke(Call.java:1812)


更新-2:

以下是我遇到的问题的最新消息。在WSDL文件中,我发现了类似的东西,

complexType name="ArrayOfString"
sequence
element maxOccurs="unbounded" name="string" type="xsd:string" / 
/sequence
/complexType

好吧,现在我打算使用这种方法,

 <element name="createRequest">
<complexType>
<sequence>
<element name="sid" type="xsd:int" /> 
<element name="creatorHandle" type="xsd:string" /> 
<element name="attrVals" type="impl:ArrayOfString" /> 
<element name="propertyValues" type="impl:ArrayOfString" /> 
<element name="template" type="xsd:string" /> 
<element name="attributes" type="impl:ArrayOfString" /> 
<element name="newRequestHandle" type="xsd:string" /> 
<element name="newRequestNumber" type="xsd:string" /> 
</sequence>
</complexType>
</element>

现在,我尝试发送参数'attrVals','attibutes'就像这样

ArrayOfstring attrVals = new ArrayOfstring();
    ArrayOfstring attributes = new ArrayOfstring();
    attrVals.setString(new String[] { "customer", "test from soapUI",
            "customer", ticketHandle, "type", "I" });
    attributes.setString(new String[] { "status", "ref_num" });

抛出以下异常

AxisFault
faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server.userException
faultSubcode: 
faultString: java.io.IOException: No serializer found for class org.tempuri.complex.data.arrays.xsd.ArrayOfstring in registry org.apache.axis.encoding.TypeMappingDelegate@11e1e67
faultActor: 
faultNode: 
faultDetail: 
{http://xml.apache.org/axis/}stackTrace:java.io.IOException: No serializer found  for class org.tempuri.complex.data.arrays.xsd.ArrayOfstring in registry org.apache.axis.encoding.TypeMappingDelegate@11e1e67
at org.apache.axis.encoding.SerializationContext.serializeActual(SerializationContext.java:1507)
at org.apache.axis.encoding.SerializationContext.serialize(SerializationContext.java:980)

1 个答案:

答案 0 :(得分:3)

上述错误已经解决。我只是使用TypeRegistryMapping类注册了ArrayOfString类,String []。现在,它不会抛出上面的序列化错误。 编辑的代码是:

    ServiceFactory factory1 = ServiceFactory.newInstance();
    QName qnTick = new QName("http://soapinterop.org/xsd", "ArrayOfString");
    Service serviceTickReq = factory1.createService(qnTick);
    // Service serviceTickReq = new org.apache.axis.client.Service();
    TypeMappingRegistry tmr = (TypeMappingRegistry) serviceTickReq
            .getTypeMappingRegistry();
    TypeMapping tm = (TypeMapping) tmr.getDefaultTypeMapping();
    tm.register(ArrayOfString.class, qnTick, new BeanSerializerFactory(
            ArrayOfString.class, qnTick), new BeanDeserializerFactory(
            ArrayOfString.class, qnTick));

    TypeMappingRegistry tmr1 = (TypeMappingRegistry) serviceTickReq
            .getTypeMappingRegistry();
    TypeMapping tm1 = (TypeMapping) tmr1.getDefaultTypeMapping();
    tm1.register(String[].class, qnTick, new BeanSerializerFactory(
            String[].class, qnTick), new BeanDeserializerFactory(
            String[].class, qnTick));