0

嗨,我正在尝试在 Google 应用引擎上创建一个 SOAP Web 服务,我正在关注这篇文章

本教程展示了一个简单的 hello world 教程,我成功运行了该程序并获得了响应

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header/>
<SOAP-ENV:Body>
<ns3:sayHelloResponse xmlns:ns3="http://example.com/">
<return>Hello, hello!</return>
</ns3:sayHelloResponse>
</SOAP-ENV:Body>

</SOAP-ENV:Envelope>

这是 SOAP1.1 格式我必须得到 SOAP 1.2 格式的响应,例如

<?xml version="1.0"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
xmlns:e="http://[app-id].appspot.com/gevents-service">
<env:Body>
</env:Body>

为此,我在 Greeter 类的顶部添加了一行:

@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING) 

,然后在 Greeter 类上运行 wsgen 命令:

C:\Users\Lenovo\workspace\HelloSoapServer1>wsgen -extension -wsdl:Xsoap1.2 -cp "
./war/WEB-INF/classes" -wsdl -keep -r "./war" -d "./war/WEB-INF/classes" -s "./s
rc" com.example.Greeter

其中 HelloSoapServer1 是项目名称,它成功创建了 SOAP1.2 格式的 wsdl 文件,然后我再次将其部署到 appengine 我期待 SOAP1.2 版本的响应输出,但响应仍然与以前相同。这里是一些代码

迎宾班

package com.example;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.xml.ws.BindingType;

@WebService
@BindingType(javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING)
public class Greeter {
  @WebMethod
  public String sayHello(String name){
    return "Hello, " + name+ "!";
  }
  @WebMethod
  public String sayGoodbye(String name){
    return "Goodbye, " + name + "!";
  }
}

生成 GreeterService.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.1.6 in JDK 6. -->
<definitions targetNamespace="http://example.com/" name="GreeterService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://example.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/">
  <types>
    <xsd:schema>
      <xsd:import namespace="http://example.com/" schemaLocation="GreeterService_schema1.xsd"/>
    </xsd:schema>
  </types>
  <message name="sayHello">
    <part name="parameters" element="tns:sayHello"/>
  </message>
  <message name="sayHelloResponse">
    <part name="parameters" element="tns:sayHelloResponse"/>
  </message>
  <message name="sayGoodbye">
    <part name="parameters" element="tns:sayGoodbye"/>
  </message>
  <message name="sayGoodbyeResponse">
    <part name="parameters" element="tns:sayGoodbyeResponse"/>
  </message>
  <portType name="Greeter">
    <operation name="sayHello">
      <input message="tns:sayHello"/>
      <output message="tns:sayHelloResponse"/>
    </operation>
    <operation name="sayGoodbye">
      <input message="tns:sayGoodbye"/>
      <output message="tns:sayGoodbyeResponse"/>
    </operation>
  </portType>
  <binding name="GreeterPortBinding" type="tns:Greeter">
    <soap12:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
    <operation name="sayHello">
      <soap12:operation soapAction=""/>
      <input>
        <soap12:body use="literal"/>
      </input>
      <output>
        <soap12:body use="literal"/>
      </output>
    </operation>
    <operation name="sayGoodbye">
      <soap12:operation soapAction=""/>
      <input>
        <soap12:body use="literal"/>
      </input>
      <output>
        <soap12:body use="literal"/>
      </output>
    </operation>
  </binding>
  <service name="GreeterService">
    <port name="GreeterPort" binding="tns:GreeterPortBinding">
      <soap12:address location="http://onemoredemo.appspot.com/hellosoapserver1"/>
    </port>
  </service>
</definitions>

GreeterService_schema1.xsd 代码是

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<xs:schema version="1.0" targetNamespace="http://example.com/" xmlns:tns="http://example.com/" xmlns:xs="http://www.w3.org/2001/XMLSchema">

  <xs:element name="sayGoodbye" type="tns:sayGoodbye"/>

  <xs:element name="sayGoodbyeResponse" type="tns:sayGoodbyeResponse"/>

  <xs:element name="sayHello" type="tns:sayHello"/>

  <xs:element name="sayHelloResponse" type="tns:sayHelloResponse"/>

  <xs:complexType name="sayHello">
    <xs:sequence>
      <xs:element name="arg0" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="sayHelloResponse">
    <xs:sequence>
      <xs:element name="return" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="sayGoodbye">
    <xs:sequence>
      <xs:element name="arg0" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="sayGoodbyeResponse">
    <xs:sequence>
      <xs:element name="return" type="xs:string" minOccurs="0"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

据我阅读一些关于 SOAP1.2 Web 服务的文章,wsgen 工具正在生成正确的 wsdl 文件,但是当我部署它时,它以 SOAP1.1 的格式给出响应,任何人都可以请帮助我为什么没有得到格式的输出SOAP1.2协议如下图

 <?xml version="1.0"?>
    <env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope"
    xmlns:e="http://[app-id].appspot.com/gevents-service">
    <env:Body>
    </env:Body>
4

1 回答 1

0

我看到你的命令开始了:

wsgen -extension -wsdl:Xsoap1.2, 但后来有-wsdl -keep -r等... 是否有可能第二次出现-wsdl覆盖第一次使用默认值 1.1?

于 2016-03-07T18:11:42.590 回答