我有下一个问题。我部署了一个Web服务,其wsdl是:
<?xml version='1.0' encoding='UTF-8'?><wsdl:definitions name="IServiceA" targetNamespace="http://servicea.service/" xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://servicea.service/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<wsdl:types>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://servicea.service/" xmlns:tns="http://servicea.service/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="printMsg" type="tns:printMsg" />
<xsd:complexType name="printMsg">
<xsd:sequence>
<xsd:element minOccurs="0" name="arg0" nillable="true" type="xsd:string" />
</xsd:sequence>
</xsd:complexType>
<xsd:element name="printMsgResponse" type="tns:printMsgResponse" />
<xsd:complexType name="printMsgResponse">
<xsd:sequence>
<xsd:element name="return" type="xsd:boolean" />
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
</wsdl:types>
<wsdl:message name="printMsgResponse">
<wsdl:part element="tns:printMsgResponse" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:message name="printMsg">
<wsdl:part element="tns:printMsg" name="parameters">
</wsdl:part>
</wsdl:message>
<wsdl:portType name="IServiceAPortType">
<wsdl:operation name="printMsg">
<wsdl:input message="tns:printMsg" name="printMsg">
</wsdl:input>
<wsdl:output message="tns:printMsgResponse" name="printMsgResponse">
</wsdl:output>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="IServiceASoapBinding" type="tns:IServiceAPortType">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" />
<wsdl:operation name="printMsg">
<soap:operation soapAction="" style="document" />
<wsdl:input name="printMsg">
<soap:body use="literal" />
</wsdl:input>
<wsdl:output name="printMsgResponse">
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="IServiceA">
<wsdl:port binding="tns:IServiceASoapBinding" name="IServiceAPort">
<soap:address location="http://localhost:9000/ServiceA" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
而且,我正在使用javax.xml.rpc包。我的实现是下一步:
package soapdemo;
import javax.xml.namespace.QName;
import javax.xml.rpc.Call;
import javax.xml.rpc.ParameterMode;
import javax.xml.rpc.Service;
import javax.xml.rpc.ServiceFactory;
public class DIIHello {
private static String qnameService = "IServiceA";
private static String qnamePort = "IServiceAPort";
private static String endpoint =
"http://localhost:9000/ServiceA";
private static String BODY_NAMESPACE_VALUE = "http://servicea.service/";
private static String ENCODING_STYLE_PROPERTY = "javax.xml.rpc.encodingstyle.namespace.uri";
private static String NS_XSD = "http://www.w3.org/2001/XMLSchema";
private static String URI_ENCODING = "http://schemas.xmlsoap.org/soap/encoding/";
public static void main(String[] args) {
try {
ServiceFactory factory =
ServiceFactory.newInstance();
Service service =
factory.createService(new QName(qnameService));
QName port = new QName(qnamePort);
Call call = service.createCall(port);
call.setTargetEndpointAddress(endpoint);
call.setProperty(Call.SOAPACTION_USE_PROPERTY,
new Boolean(true));
call.setProperty(Call.SOAPACTION_URI_PROPERTY, "");
call.setProperty(ENCODING_STYLE_PROPERTY,
URI_ENCODING);
QName QNAME_TYPE_STRING = new QName(NS_XSD, "string");
call.setReturnType(QNAME_TYPE_STRING);
call.setOperationName(new QName(BODY_NAMESPACE_VALUE, "printMsg"));
call.addParameter("arg0", QNAME_TYPE_STRING,
ParameterMode.IN);
Object[] inParams = new Object[1];
inParams[0] = new String("Hola");
String result = (String)call.invoke(inParams);
System.out.println(result);
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
找到WS,但其参数(arg0)为空。我不知道我能做什么,我不知道我的错误在哪里。
顺便说一下,当我使用wsimport生成客户端时,服务确实收到了值,然后是这个实现的东西。
如果有人能帮助我,请。
感谢。