问题描述
我正在尝试从Java后端服务访问用C#编写的基于SOAP的旧系统.此C#应用程序正在寻找 AddressHeader 在每个请求中填充特定值.我正在使用Apache CXF创建对此服务的请求.不幸的是,对于我一生来说,我无法找到如何将此地址标头添加到每个请求中.有谁知道Java中的等效语言以及如何使用Apache CXF添加它?
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?
推荐答案
地址标头与 SOAP
标头相同,因此我们只需要向每个请求添加一个特定的SOAP标头,以便能够成功拨打电话.
这是我在互联网上找到的示例.
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);
请参考以下链接,希望它对您有用.
https://dzone.com/articles/apache-cxf-how-add-custom-soap-0
https://dzone.com/articles/apache-cxf-how-添加自定义肥皂
请随时告诉我是否有什么我可以帮助的.
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.
这篇关于什么是C#WCF AddressHeader的Java Apache CXF等效项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!