在 Web 服务中接收参数时出现问题

发布于 2024-10-30 03:51:26 字数 4722 浏览 0 评论 0原文

我有下一个问题。我部署了一个 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 生成客户端时,服务确实收到了该值,然后是此实现的一些内容。

如果有人可以帮助我,请。

谢谢。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文