What is the Java Apache CXF equivalent of C# WCF AddressHeader?

纵然是瞬间 提交于 2021-02-11 13:51:04

问题


I'm trying to access an old SOAP based system written in C# from a Java backend service. This C# application is looking for an AddressHeader to be populated with a specific value on every request. I'm using Apache CXF to create the requests to this service. Unfortunately, for the life of me, I cannot find out how to add this address header to each of the requests. Does anyone know what the equivalent in Java is and how to add it using Apache CXF?


回答1:


The address header is the same as the SOAP header, hence we only need to add a particular SOAP header to every request so that be capable of making a successful call.
Here is an example I found on the internet.

ClientProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(singz.ws.cxf.sample.SampleServiceInterface.class);
factory.setAddress("http://xxx.xxx.com/services/SampleService/v1");
        SampleServiceInterface serviceClient = (SampleServiceInterface) factory.create();
        Client proxy = ClientProxy.getClient(serviceClient);
        List<Header> headersList = new ArrayList<Header>();
        Header testSoapHeader1 = new Header(new QName("uri:singz.ws.sample", "soapheader1"), "SOAP Header Message 1", new JAXBDataBinding(String.class));
        Header testSoapHeader2 = new Header(new QName("uri:singz.ws.sample", "soapheader2"), "SOAP Header Message 2", new JAXBDataBinding(String.class));
        headersList.add(testSoapHeader1);
        headersList.add(testSoapHeader2);
        proxy.getRequestContext().put(Header.HEADER_LIST, headersList);

Please refer to the below links, wish it is useful to you.
https://dzone.com/articles/apache-cxf-how-add-custom-soap-0
How do you add a Soap Header defined in a wsdl to a web service client in CXF?
https://dzone.com/articles/apache-cxf-how-add-custom-soap
Feel free to let me know if there is anything I can help with.



来源:https://stackoverflow.com/questions/59431793/what-is-the-java-apache-cxf-equivalent-of-c-sharp-wcf-addressheader

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!