使用 axis2 和 java2wdsl 在所有节点中重复命名空间

发布于 2024-08-27 16:46:19 字数 3498 浏览 8 评论 0原文

我正在使用 eclipse 和 axis2 1.4.1 侧面来生成 Web 服务。 我的问题是,在生成过程中,命名空间在所有节点中重复。如下所示,ns4 被重复而不是在中声明 NewOperationResponse 节点。

如何让 java2wdsl (或 eclipse)自动生成(仅在父节点或顶级节点中)? 我需要更改 wsdl 或 xsd 上的任何内容吗?

谢谢!

WS 响应

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<NewOperationResponse xmlns="http://www.example.org/Test">
<out>
  <ns4:areaCode xmlns:ns4="http://www.example.org/Test/Simple">0</ns4:areaCode> 
  <ns4:exchange xmlns:ns4="http://www.example.org/Test/Simple">0</ns4:exchange> 
  <ns4:number xmlns:ns4="http://www.example.org/Test/Simple">12</ns4:number> 
</out>
</NewOperationResponse>
</soapenv:Body>
</soapenv:Envelope>

WSDL

 <wsdl:types>

  <xsd:schema targetNamespace="http://www.example.org/Test"
   xmlns:simple="http://www.example.org/Test/Simple" 
   elementFormDefault="qualified" attributeFormDefault="unqualified" version="2.1">

   <xsd:import namespace="http://www.example.org/Test/Simple" schemaLocation="Simple.xsd" />
   <xsd:element name="NewOperation">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element name="in" type="xsd:string" />
     </xsd:sequence>
    </xsd:complexType>
   </xsd:element>

   <xsd:element name="NewOperationResponse">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element name="out" type="simple:Phone" />
     </xsd:sequence>
    </xsd:complexType>
   </xsd:element>

  </xsd:schema>
 </wsdl:types>

 <wsdl:message name="NewOperationRequest">
  <wsdl:part element="tns:NewOperation" name="parameters" />
 </wsdl:message>
 <wsdl:message name="NewOperationResponse">
  <wsdl:part element="tns:NewOperationResponse" name="parameters" />
 </wsdl:message>

 <wsdl:portType name="Test">
  <wsdl:operation name="NewOperation">
   <wsdl:input message="tns:NewOperationRequest" />
   <wsdl:output message="tns:NewOperationResponse" />
  </wsdl:operation>
 </wsdl:portType>
 <wsdl:binding name="TestSOAP" type="tns:Test">
  <soap:binding style="document"
   transport="http://schemas.xmlsoap.org/soap/http" />
  <wsdl:operation name="NewOperation">
   <soap:operation soapAction="" />
   <wsdl:input>
    <soap:body use="literal" />
   </wsdl:input>
   <wsdl:output>
    <soap:body use="literal" />
   </wsdl:output>
  </wsdl:operation>
 </wsdl:binding>
 <wsdl:service name="Test">
  <wsdl:port binding="tns:TestSOAP" name="TestSOAP">
   <soap:address location="http://localhost:8084/WSDLProject/services/Test" />
  </wsdl:port>
 </wsdl:service>
</wsdl:definitions>

简单.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.example.org/Test/Simple"
 xmlns:xs="http://www.w3.org/2001/XMLSchema" 
 elementFormDefault="qualified"
 attributeFormDefault="qualified">

 <xs:complexType name="Phone">
  <xs:sequence>
   <xs:element name="areaCode" type="xs:int" />
   <xs:element name="exchange" type="xs:int" />
   <xs:element name="number" type="xs:int" />
  </xs:sequence>
 </xs:complexType>
</xs:schema>

I am using eclipse and axis2 1.4.1 facet to generate a webservice.
My problem is that in the generation process, the namespaces are being repeated in all nodes. As you can see below, ns4 is repeated instead of being declared in
NewOperationResponse node.

How can I make java2wdsl (or eclipse) generate that automatically (only in parent node or top node) ?
Do I have to change anything on wsdl or xsd ?

Thanks!

WS Response

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<NewOperationResponse xmlns="http://www.example.org/Test">
<out>
  <ns4:areaCode xmlns:ns4="http://www.example.org/Test/Simple">0</ns4:areaCode> 
  <ns4:exchange xmlns:ns4="http://www.example.org/Test/Simple">0</ns4:exchange> 
  <ns4:number xmlns:ns4="http://www.example.org/Test/Simple">12</ns4:number> 
</out>
</NewOperationResponse>
</soapenv:Body>
</soapenv:Envelope>

WSDL

 <wsdl:types>

  <xsd:schema targetNamespace="http://www.example.org/Test"
   xmlns:simple="http://www.example.org/Test/Simple" 
   elementFormDefault="qualified" attributeFormDefault="unqualified" version="2.1">

   <xsd:import namespace="http://www.example.org/Test/Simple" schemaLocation="Simple.xsd" />
   <xsd:element name="NewOperation">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element name="in" type="xsd:string" />
     </xsd:sequence>
    </xsd:complexType>
   </xsd:element>

   <xsd:element name="NewOperationResponse">
    <xsd:complexType>
     <xsd:sequence>
      <xsd:element name="out" type="simple:Phone" />
     </xsd:sequence>
    </xsd:complexType>
   </xsd:element>

  </xsd:schema>
 </wsdl:types>

 <wsdl:message name="NewOperationRequest">
  <wsdl:part element="tns:NewOperation" name="parameters" />
 </wsdl:message>
 <wsdl:message name="NewOperationResponse">
  <wsdl:part element="tns:NewOperationResponse" name="parameters" />
 </wsdl:message>

 <wsdl:portType name="Test">
  <wsdl:operation name="NewOperation">
   <wsdl:input message="tns:NewOperationRequest" />
   <wsdl:output message="tns:NewOperationResponse" />
  </wsdl:operation>
 </wsdl:portType>
 <wsdl:binding name="TestSOAP" type="tns:Test">
  <soap:binding style="document"
   transport="http://schemas.xmlsoap.org/soap/http" />
  <wsdl:operation name="NewOperation">
   <soap:operation soapAction="" />
   <wsdl:input>
    <soap:body use="literal" />
   </wsdl:input>
   <wsdl:output>
    <soap:body use="literal" />
   </wsdl:output>
  </wsdl:operation>
 </wsdl:binding>
 <wsdl:service name="Test">
  <wsdl:port binding="tns:TestSOAP" name="TestSOAP">
   <soap:address location="http://localhost:8084/WSDLProject/services/Test" />
  </wsdl:port>
 </wsdl:service>
</wsdl:definitions>

simple.xsd

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.example.org/Test/Simple"
 xmlns:xs="http://www.w3.org/2001/XMLSchema" 
 elementFormDefault="qualified"
 attributeFormDefault="qualified">

 <xs:complexType name="Phone">
  <xs:sequence>
   <xs:element name="areaCode" type="xs:int" />
   <xs:element name="exchange" type="xs:int" />
   <xs:element name="number" type="xs:int" />
  </xs:sequence>
 </xs:complexType>
</xs:schema>

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你是年少的欢喜 2024-09-03 16:46:19

怎么样

<schema elementFormDefaultQualified="false"/> 

添加内容

<service>

以及在 services.xml

?至少这对我有用,正如您从 SOAP 响应中看到的那样:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:getTelalertByEscalationResponse xmlns:ns="http://ofrick.com"><return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax237:TelalertEntry"><alertDefName xsi:nil="true" /><alertId>1234</alertId><client>cwp1088</client><timeStamp>201405202254</timeStamp><tts>and this is a test tts</tts></return></ns:getTelalertByEscalationResponse></soapenv:Body></soapenv:Envelope>

and what about adding

<schema elementFormDefaultQualified="false"/> 

inside

<service>

in your services.xml ?

At least this worked for me, as you can see from the SOAP response:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:getTelalertByEscalationResponse xmlns:ns="http://ofrick.com"><return xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ax237:TelalertEntry"><alertDefName xsi:nil="true" /><alertId>1234</alertId><client>cwp1088</client><timeStamp>201405202254</timeStamp><tts>and this is a test tts</tts></return></ns:getTelalertByEscalationResponse></soapenv:Body></soapenv:Envelope>
木落 2024-09-03 16:46:19

在您的 wsdl 架构声明中切换到使用 elementFormDefault="uqualified" 而不是使用 elementFormDefault="qualified"

In your wsdl schema declaration switch to using elementFormDefault="uqualified" as opposed to using elementFormDefault="qualified"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文