关于webService发布的wsdl中的import问题解决
2013-07-26 14:09
162 查看
大家都知道jdk1.6及以后都支持了对webService的原生态的支持;它在发布时会生成一个wsdl和一个xsd(一个类只生成一个xsd)所以就保留了引用关系,如下:
但是由于osb平台目前不能识别这种引用关系,即所有引用都应该在一个文件中可见;为了解决这个问题:可以采用的方法就是手动把生成的这两个文件(wsdl和xsd文件)手动合并成一个文件比如取名"HelloService.wsdl”;把文件放到classpath路径下,或者发布webService需要的地方,然后在发布webService之前,修改webservice的定义;退如下:
添加“wsdlLocation="HelloService.wsdl" ”;这个就可以了;
得到结果将是:
对于另一种import问题就是当我们定义一个接口一个实现类的时候,如果两个接口和实现类不一个package中时,也会出现对wsdl的引用问题,此时只需要在实现类的annotation中添加endpointInterface="com.zzz.jaxws.service.HelloService"(即接口类包路径名);
参考:http://stackoverflow.com/questions/16030574/jax-ws-has-xsd-schema-in-different-url(不过我不得不声名其实拼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. --> - <!-- 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文件这个方法我也想到了,只是还没有来得及去试试就先看了这个文章,嘿嘿)
相关文章推荐
- 关于引用了WebService的项目移植发布问题解决
- 解决cxf+spring发布的webservice缺少<wsdl:types>和<wsdl:message>标签的问题
- 解决cxf+spring发布的webservice缺少<wsdl:types>和<wsdl:message>标签的问题
- 解决cxf+bboss发布的webservice缺少<wsdl:types>和<wsdl:message>标签的问题
- axis客户端调用jws发布的webservice要5分钟才能返回问题解决
- 使用spring.net发布webservice时函数重名的问题的解决办法
- 关于使用cocoaPods,import导入时第三方库头文件没有提示问题的解决办法
- WebService发布与调用问题:expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {http://schemas.xmlsoap.org/wsdl/}def
- 关于Qt使用windeployqt发布相关问题解决办法--个人整理
- 使用spring.net发布webservice时函数重名的问题的解决办法
- 关于.net 项目发布到iis上后,点开aspx页面就出问题的部分解决
- VS2012 webservice的创建并在iis上发布,发布完后解决“测试窗体只能用于来自本地计算机的请求.”问题视频教程
- C#发布WebService提供使用时候,通过服务器解决前端js跨域访问问题
- WebService发布与调用问题:expected: {http://schemas.xmlsoap.org/soap/envelope/}Envelope but found: {http://schemas.xmlsoap.org/wsdl/}definitions
- 解决关于那些文件夹Unity可以发布出去的问题
- 关于BPEL发布成WSDL后调用的问题
- 解决WSDL.EXE不能解析外部Import的XSD的问题
- 关于 hibernate import file not found: /import.sql 问题的解决
- 关于Win7旗舰版配置iis发布WebService的一些问题
- 关于Cocos2d-x发布游戏的时候遇到的问题和解决