SOAP Web服务的XML响应格式

时间:2012-07-30 10:28:46

标签: web-services google-app-engine soap wsdl

您好我正在尝试在Google应用引擎上创建SOAP网络服务我正在关注此article

本教程展示了一个简单的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版本中的响应输出但仍然响应与之前的相同。这里有一些代码

Greeter Class

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>

1 个答案:

答案 0 :(得分:0)

我看到你的命令开始了:

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