zoukankan      html  css  js  c++  java
  • 关于webService发布的wsdl中的import问题解决

    大家都知道jdk1.6及以后都支持了对webService的原生态的支持;它在发布时会生成一个wsdl和一个xsd(一个类只生成一个xsd)所以就保留了引用关系,如下:

      <?xml version="1.0" encoding="UTF-8" ?> 
    - <!--  Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. 
      --> 
    - <!--  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 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://jaxws.zzz/jaxws/hello" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://jaxws.zzz/jaxws/hello" name="HelloService">
    - <types>
    - <xsd:schema>
      <xsd:import namespace="http://jaxws.zzz/jaxws/hello" schemaLocation="http://localhost:8080/services/HelloService?xsd=1" /> 
      </xsd:schema>
      </types>
    - <message name="sayHello">
      <part name="parameters" element="tns:sayHello" /> 
      </message>
    - <message name="sayHelloResponse">
      <part name="parameters" element="tns:sayHelloResponse" /> 
      </message>
    - <portType name="HelloService">
    - <operation name="sayHello">
      <input message="tns:sayHello" /> 
      <output message="tns:sayHelloResponse" /> 
      </operation>
      </portType>
    - <binding name="HelloServicePortBinding" type="tns:HelloService">
      <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
    - <operation name="sayHello">
      <soap:operation soapAction="" /> 
    - <input>
      <soap:body use="literal" /> 
      </input>
    - <output>
      <soap:body use="literal" /> 
      </output>
      </operation>
      </binding>
    - <service name="HelloService">
    - <port name="HelloServicePort" binding="tns:HelloServicePortBinding">
      <soap:address location="http://localhost:8080/services/HelloService" /> 
      </port>
      </service>
      </definitions>

    但是由于osb平台目前不能识别这种引用关系,即所有引用都应该在一个文件中可见;为了解决这个问题:可以采用的方法就是手动把生成的这两个文件(wsdl和xsd文件)手动合并成一个文件比如取名"HelloService.wsdl”;把文件放到classpath路径下,或者发布webService需要的地方,然后在发布webService之前,修改webservice的定义;退如下:

    @WebService(serviceName = "HelloService", portName = "HelloServicePort", targetNamespace = "http://jaxws.zzz/jaxws/hello",wsdlLocation="HelloService.wsdl")
    @SOAPBinding(style = SOAPBinding.Style.DOCUMENT, use = SOAPBinding.Use.LITERAL, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
    public class HelloService {
        @WebMethod
        public String sayHello(String s) {
            System.out.println("hello," + s);
            return s;
        }
    }

    添加“wsdlLocation="HelloService.wsdl" ”;这个就可以了;

    得到结果将是:

      <?xml version="1.0" encoding="UTF-8" ?> 
    - <!--  Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. 
      --> 
    - <!--  Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is JAX-WS RI 2.1.6 in JDK 6. 
      --> 
    - <!--  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 xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://jaxws.zzz/jaxws/hello" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://jaxws.zzz/jaxws/hello" name="HelloService">
    - <types>
    - <xs:schema xmlns:tns="http://jaxws.zzz/jaxws/hello" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="1.0" targetNamespace="http://jaxws.zzz/jaxws/hello">
      <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:schema>
      </types>
    - <message name="sayHello">
      <part name="parameters" element="tns:sayHello" /> 
      </message>
    - <message name="sayHelloResponse">
      <part name="parameters" element="tns:sayHelloResponse" /> 
      </message>
    - <portType name="HelloService">
    - <operation name="sayHello">
      <input message="tns:sayHello" /> 
      <output message="tns:sayHelloResponse" /> 
      </operation>
      </portType>
    - <binding name="HelloServicePortBinding" type="tns:HelloService">
      <soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document" /> 
    - <operation name="sayHello">
      <soap:operation soapAction="" /> 
    - <input>
      <soap:body use="literal" /> 
      </input>
    - <output>
      <soap:body use="literal" /> 
      </output>
      </operation>
      </binding>
    - <service name="HelloService">
    - <port name="HelloServicePort" binding="tns:HelloServicePortBinding">
      <soap:address location="http://localhost:8080/services/HelloService" /> 
      </port>
      </service>
      </definitions>

    对于另一种import问题就是当我们定义一个接口一个实现类的时候,如果两个接口和实现类不一个package中时,也会出现对wsdl的引用问题,此时只需要在实现类的annotation中添加endpointInterface="com.zzz.jaxws.service.HelloService"(即接口类包路径名);

    参考:http://stackoverflow.com/questions/16030574/jax-ws-has-xsd-schema-in-different-url(不过我不得不声名其实拼wsdl文件这个方法我也想到了,只是还没有来得及去试试就先看了这个文章,嘿嘿)

  • 相关阅读:
    泛微协同OA制造业解决方案
    泛微协同OA房地产行业解决方案
    基于内置web工作流的政府OA解决方案
    泛微协同OA广告行业解决方案
    成功导入数据
    首页做完了
    终于知道如何才能取得HtmlEditor里的数据了
    国庆放假了!
    最近这两天
    Dictionary<string, string>是一个泛型使用说明
  • 原文地址:https://www.cnblogs.com/roilat/p/3216996.html
Copyright © 2011-2022 走看看