在JAX-WS客户端上编码/解码msbin1

时间:2016-04-15 19:11:44

标签: java jax-ws

我正在使用一个重新收录Content-Type的网络服务:" application / soap + msbin1"但它似乎需要一个特殊的编码来请求,因为我收到了#34; Bad Request"关于ws的反应

public class pruebaWS {
public static void main(String[] args) {


    JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean();
    proxyFactory.setServiceClass(IMercadosCanalService.class);
    proxyFactory.setAddress("http://webbmgdesa2.rio.ar.bsch:5670/MercadosCanalService.svc");
    IMercadosCanalService port = (IMercadosCanalService) proxyFactory.create();
    Client client = ClientProxy.getClient(port); 

    HTTPConduit httpConduit = (HTTPConduit) client.getConduit();
    HTTPClientPolicy policy = new HTTPClientPolicy();
    policy.setContentType("application/soap+msbin1");
    httpConduit.setClient(policy);
    try {
        port.consultaDeOrdenes(new ConsultaOrdenCanalRequest());
    } catch (IMercadosCanalServiceConsultaDeOrdenesMercadosServiceFaultFaultFaultMessage e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

在发送请求之前如何对请求进行编码的任何想法?

Throwable occurred: org.apache.cxf.interceptor.Fault: Response was of unexpected text/html ContentType.  Incoming portion of HTML stream: Bad Request
at org.apache.cxf.interceptor.StaxInInterceptor.handleMessage(StaxInInterceptor.java:73)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
at org.apache.cxf.endpoint.ClientImpl.onMessage(ClientImpl.java:664)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponseInternal(HTTPConduit.java:2160)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.handleResponse(HTTPConduit.java:2040)
at org.apache.cxf.transport.http.HTTPConduit$WrappedOutputStream.close(HTTPConduit.java:1965)
at org.apache.cxf.transport.AbstractConduit.close(AbstractConduit.java:66)
at org.apache.cxf.transport.http.HTTPConduit.close(HTTPConduit.java:627)
at org.apache.cxf.interceptor.MessageSenderInterceptor$MessageSenderEndingInterceptor.handleMessage(MessageSenderInterceptor.java:62)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:478)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:308)
at org.apache.cxf.endpoint.ClientImpl.invoke(ClientImpl.java:260)
at org.apache.cxf.frontend.ClientProxy.invokeSync(ClientProxy.java:73)
at org.apache.cxf.jaxws.JaxWsClientProxy.invoke(JaxWsClientProxy.java:124)
at $Proxy60.consultaDeOrdenes(Unknown Source)
at com.rio.common.wsERI.pruebaWS.main(pruebaWS.java:35)

1 个答案:

答案 0 :(得分:0)

使用此内容类型是强制性要求吗?可以切换到soap + xml吗?使用更具文档性的标准会更简单。

无论如何,我发现您可以尝试使用此插件对您的请求进行编码:https://github.com/GDSSecurity/WCF-Binary-SOAP-Plug-In