我正在尝试使用CXF为.NET Web服务编写Java客户端,但在调用" client.getConduit()"时,它会抛出异常 - org.apache.cxf.ws.policy.PolicyException:没有任何政策选择可以满足。请帮忙!
以下是代码段 -
ServiceClass service = new ServiceClass();
PortClass port = service.getPort(ServiceClass.class);
Client client = ClientProxy.getClient(port);
HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
final HTTPClientPolicy httpClientPolicy = httpConduit.getClient();
httpClientPolicy.setAllowChunking(false);
httpClientPolicy.setAutoRedirect(true);
final BindingProvider bindingProvider = (BindingProvider) port;
final Map<String, Object> requestContext = bindingProvider.getRequestContext();
final Credentials credentials = new NTCredentials(USERNAME, PASSWORD, "", DOMAIN);
requestContext.put(Credentials.class.getName(), credentials);
requestContext.put(AsyncHTTPConduit.USE_ASYNC, Boolean.TRUE);
以下是来自wsdl的ws政策代码段 -
<wsp:Policy wsu:Id="httpsendpoint_policy">
<wsp:ExactlyOne>
<wsp:All>
<http:NegotiateAuthentication xmlns:http="http://schemas.microsoft.com/ws/06/2004/policy/http" />
<sp:TransportBinding xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy">
<wsp:Policy>
<sp:TransportToken>
<wsp:Policy>
<sp:HttpsToken RequireClientCertificate="false" />
</wsp:Policy>
</sp:TransportToken>
<sp:AlgorithmSuite>
<wsp:Policy>
<sp:Basic256 />
</wsp:Policy>
</sp:AlgorithmSuite>
<sp:Layout>
<wsp:Policy>
<sp:Strict />
</wsp:Policy>
</sp:Layout>
</wsp:Policy>
</sp:TransportBinding>
<wsaw:UsingAddressing />
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>