问题太长了,但我希望预先提供所有信息。
我有以下几类:
package test.api.soap.server;
public class TestClassA {
public TestClassA() {
}
public String doA() {
System.out.println("Start doA()");
return "In do A";
}
}
I want to expose it as web service but not directly so i created wrapper class: package test.api.soap.server;
import javax.jws.WebMethod;
import javax.jws.WebService;
@WebService
public class MyClientApiV2_5 {
public MyClientApiV2_5() {
}
@WebMethod
public TestClassA getTestClassA() {
return new TestClassA();
}
}
我在ant任务中使用标准载荷创建服务器WSDL:
<target name="Create-JAXWS-SOAP-Server">
<echo message="Generate SOAP server stubs" />
<exec executable="${wsgen-cmd}">
<arg value="-verbose" />
<arg value="-classpath" />
<arg value="${build}" />
<arg value="-wsdl" />
<arg value="-d" />
<arg value="${build}" />
<arg value="-r" />
<arg value="wsdl" />
<arg value="-s" />
<arg value="${src}" />
<arg value="-keep" />
<arg value="test.api.soap.server.MyClientApiV2_5" />
</exec>
</target>
The out come are 2 files: MyClientApiV25Service.wsdl
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI s version is JAX-WS RI 2.2.3-b01-. -->
<definitions targetNamespace="http://server.soap.api.test/" name="MyClientApiV2_5Service" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:wsp="http://www.w3.org/ns/ws-policy" xmlns:tns="http://server.soap.api.test/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsp1_2="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<types>
<xsd:schema>
<xsd:import namespace="http://server.soap.api.test/" schemaLocation="MyClientApiV25Service_schema1.xsd"/>
</xsd:schema>
</types>
<message name="getTestClassA">
<part name="parameters" element="tns:getTestClassA"/>
</message>
<message name="getTestClassAResponse">
<part name="parameters" element="tns:getTestClassAResponse"/>
</message>
<portType name="MyClientApiV2_5">
<operation name="getTestClassA">
<input wsam:Action="http://server.soap.api.test/MyClientApiV2_5/getTestClassARequest" message="tns:getTestClassA"/>
<output wsam:Action="http://server.soap.api.test/MyClientApiV2_5/getTestClassAResponse" message="tns:getTestClassAResponse"/>
</operation>
</portType>
<binding name="MyClientApiV2_5PortBinding" type="tns:MyClientApiV2_5">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="getTestClassA">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="MyClientApiV2_5Service">
<port name="MyClientApiV2_5Port" binding="tns:MyClientApiV2_5PortBinding">
<soap:address location="REPLACE_WITH_ACTUAL_URL"/>
</port>
</service>
</definitions>
<>MyClientApiV25SER_schema1.xsd
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://server.soap.api.test/" xmlns:tns="http://server.soap.api.test/" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="getTestClassA" type="tns:getTestClassA"/>
<xs:element name="getTestClassAResponse" type="tns:getTestClassAResponse"/>
<xs:complexType name="getTestClassA">
<xs:sequence/>
</xs:complexType>
<xs:complexType name="getTestClassAResponse">
<xs:sequence>
<xs:element name="return" type="tns:testClassA" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="testClassA">
<xs:sequence/>
</xs:complexType>
</xs:schema>
我制造了客户的麻烦:
<target name="Create-JAXWS-SOAP-Client" >
<echo message="Generate SOAP client stubs" />
<exec executable="${wsimport-cmd}">
<arg value="-verbose" />
<arg value="-keep" />
<arg value="-s" />
<arg value="${src}" />
<arg value="-d" />
<arg value="${build}" />
<arg value="-p" />
<arg value="test.api.soap.client.stubs" />
<arg value="wsdlMyClientApiV25Service.wsdl" />
</exec>
</target>
然后,我写上简单的客户类别,以获得网络服务:
package test.api.soap.client;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.namespace.QName;
import test.api.soap.client.stubs.MyClientApiV25;
import test.api.soap.client.stubs.MyClientApiV25Service;
import test.api.soap.client.stubs.TestClassA;
public class SampleClient {
private MyClientApiV25 api = null;
static MyClientApiV25Service service;
public SampleClient() throws MalformedURLException {
api = service.getMyClientApiV25Port();
TestClassA testClass = api.getTestClassA();
testClass.doA();
}
}
The problem is: Writing testClass.doA(); returns:
测试ClassA的类型没有定义。
任何建议?