我简要说明:
如何让wsdl2java生成SOAP 1.2绑定?
详细说明:
我使用wsdl2java
工具(apache cxf 3.0.2)为wsdl生成了java服务类:
MBA-Anton:bin asmirnov$ ./wsdl2java -server -catalog /tmp/wsdl/catalog -d /tmp/onvif/server http://www.onvif.org/onvif/ver10/network/wsdl/remotediscovery.wsdl
然后我创建了服务代码并运行它,它正在运行:
public static void main(String args[]) throws InterruptedException {
System.out.println("Starting Server");
Endpoint.publish("udp://239.255.255.250:3702", new DiscoveryService());
System.out.println("Server ready...");
Thread.sleep(10 * 60 * 1000); // 10 min
System.out.println("Server exiting");
System.exit(0);
}
开始记录:
Starting Server
28.11.2014 19:51:59 org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://www.onvif.org/ver10/network/wsdl}DiscoveryService from class org.onvif.ver10.network.wsdl.DiscoveryLookupPort
28.11.2014 19:52:00 org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be udp://239.255.255.250:3702
28.11.2014 19:52:00 org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromWSDL
INFO: Creating Service {http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01}Discovery from WSDL: classpath:/org/apache/cxf/ws/discovery/wsdl/wsdd-discovery-1.1-wsdl-os.wsdl
28.11.2014 19:52:00 org.apache.cxf.endpoint.ServerImpl initDestination
INFO: Setting the server's publish address to be soap.udp://239.255.255.250:3702
28.11.2014 19:52:00 org.apache.cxf.wsdl.service.factory.ReflectionServiceFactoryBean buildServiceFromClass
INFO: Creating Service {http://docs.oasis-open.org/ws-dd/ns/discovery/2009/01}DiscoveryProxy from class org.apache.cxf.jaxws.support.DummyImpl
Server ready...
开始后我就进入了日志:
28.11.2014 19:52:01 org.apache.cxf.phase.PhaseInterceptorChain doDefaultLogging
WARNING: Interceptor for {http://www.onvif.org/ver10/network/wsdl}DiscoveryService has thrown exception, unwinding now
org.apache.cxf.binding.soap.SoapFault: A SOAP 1.2 message is not valid when sent to a SOAP 1.1 only endpoint.
at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:168)
at org.apache.cxf.binding.soap.interceptor.ReadHeadersInterceptor.handleMessage(ReadHeadersInterceptor.java:65)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:307)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)
at org.apache.cxf.transport.udp.UDPDestination$MCastListener$2.run(UDPDestination.java:106)
at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$3.run(AutomaticWorkQueueImpl.java:428)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:895)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:918)
at org.apache.cxf.workqueue.AutomaticWorkQueueImpl$AWQThreadFactory$1.run(AutomaticWorkQueueImpl.java:353)
at java.lang.Thread.run(Thread.java:695)
然后我尝试使用ONVIF客户端(使用WS-Discovery查找设备)发现服务,并且我在日志中收到相同的错误。这让我觉得wsdl2java生成了SOAP 1.1绑定,而我的webservice无法解析SOAP 1.2客户端消息。
如何让wsdl2java生成SOAP 1.2绑定?
PS。春天它是可行的:
<soap:soapBinding mtomEnabled="true" version="1.2"/>