开发者

Problem receiving parameters in web services

I have the next problem. I have a web service deployed, its wsdl is:

<?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 nam开发者_开发问答e="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>

And, I'm using the javax.xml.rpc package. My implementation is next:

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

The WS is located, but its argument (arg0) came null. I dont know what can I do, I dont know where is my error.

By the way, when I use wsimport to generate the client, the service does receive the value, then is something with this implementation.

Please, if anyone could help me.

Thanks.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜