Axis Web服务客户端

时间:2013-08-13 13:48:56

标签: java client axis

抱歉我的英语。 我是网络服务的新手。

我有轴网络服务:

<?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>

我从Java客户端访问此服务。试试这个:

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();
}

}

但抛出异常:

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

服务器接收请求,在日志文件中我看到:

= 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>
=======================================================

请帮忙。

1 个答案:

答案 0 :(得分:1)

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