简体   繁体   中英

Axis web service client

sorry for my English. I am new to web services.

I have axis web service:

<?xml version="1.0" encoding="UTF-8"?>
<deployment xmlns="http://xml.apache.org/axis/wsdd/"     xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
...
  <service name="ServerPt" provider="java:RPC" style="wrapped" use="literal">
...
      <operation name="getStop" qname="operNS:getStop" xmlns:operNS="urn:StopServer" returnQName="return" returnType="rtns:Stop" xmlns:rtns="urn:StopServer" >
        <parameter qname="id" type="tns:long" xmlns:tns="http://www.w3.org/2001/XMLSchema"/>
      </operation>
...
      <parameter name="allowedMethods" value="... getStop ..."/>
...
      <typeMapping
        xmlns:ns="urn:StopServer"
        qname="ns:Stop"
        type="java:net.fist.st.stops.soap.server.Stop"
        serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"
        deserializer="org.apache.axis.encoding.ser.BeanDeserializerFactory"
        encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
      />
 ...
  </service>
 ...
</deployment>

And I wand access to this service from java client. Trying this:

public static void main(String[] args) 
{
try
{
    String endpoint = "http://192.168.0.1:28080/ws/services/ServerPt";
    Service s = new Service();
    Call c = (Call) s.createCall();
    c.setTargetEndpointAddress(endpoint);

    c.addParameter("id",org.apache.axis.Constants.XSD_LONG,javax.xml.rpc.ParameterMode.IN);
    c.setReturnType(new QName("urn:StopServer", "rtns:Stop"), Stop.class);
    c.registerTypeMapping(Stop.class, new QName("urn:StopServer", "rtns:Stop"), new BeanSerializerFactory(Stop.class, new QName("urn:StopServer", "rtns:Stop")), new BeanDeserializerFactory(Stop.class, new QName("urn:StopServer", "rtns:Stop")));
    c.setOperation("getStop");

    Stop st = (Stop)c.invoke( new Object[] { new Long(295) } );

    System.out.println(st.getCode().toString());
} catch(Exception e)
{
    e.printStackTrace();
}

}

But thrown exception:

org.xml.sax.SAXException: SimpleDeserializer encountered a child element, which is NOT expected, in something it was trying to deserialize.

Server receive request, and in log files I see:

= Elapsed: 117 milliseconds
= In message: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><getStop xmlns=""><arg0 xsi:type="xsd:long">295</arg0></getStop></soapenv:Body></soapenv:Envelope>
= Out message: <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><getStopResponse xmlns=""><return><id>295</id><name>Lupe</name><country>GB</country><district> </district><code>250</code><codeInf>094811</codeInf><railCode>25</railCode></return></getStopResponse></soapenv:Body></soapenv:Envelope>
=======================================================

Please help.

恕我直言,您最好使用wsdl2java生成客户端,而不是编写自己的特殊代码来使用Web服务。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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