问题
While trying to access a webservice through a client, I am not able to get the requestContext. I am trying to access the requestContext like this:
QuerySysStatService querySystem=new QuerySysStatService_Impl(wsdl);
QuerySysStatPortType qport=querySystem.getQuerySysStatPortType();
Map<String, Object> rContext =((BindingProvider)qport).getRequestContext();
But when I execute:
((BindingProvider) qport)
I get:
java.lang.ClassCastException: com.demo.client.service.QuerySysStatPortType_Stub cannot be cast to javax.xml.ws.BindingProvider
Any suggestions / help is appreciated. Thanks in advance.
回答1:
I found that:
((javax.xml.ws.BindingProvider) qport)
can safely be called on WSDL interfaces generated with JAX-WS (bywsimport
)((javax.xml.rpc.Stub) qport)
can safely be called on JAX-RPC clients (created byclientgen
)
In my case I created the WSDL interfaces with clientgen
(JAX-RPC), so the properties could be set as below:
javax.xml.rpc.Stub stub = (javax.xml.rpc.Stub) qport;
stub._setProperty("KEY","Value");
来源:https://stackoverflow.com/questions/9946284/clientgen-generated-porttype-stub-cannot-be-cast-to-javax-xml-ws-bindingprovider