java CXF 如何在没有 Spring 的情况下在 CXF 端口上设置 SoapVersion

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4248098/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 05:30:30  来源:igfitidea点击:

CXF How to set SoapVersion on CXF port without Spring

javaconfigurationjax-wscxf

提问by reef

I am currently working on a Web Service client using CXF without Spring configuration files.

我目前正在使用没有 Spring 配置文件的 CXF 开发 Web 服务客户端。

It works pretty well but I cannot figure out how to set the binding SoapVersion using the Java Api. Using a Spring file this is done as the following:

它工作得很好,但我不知道如何使用 Java Api 设置绑定 SoapVersion。使用 Spring 文件,这是按以下方式完成的:

<jaxws:binding>
    <soap:soapBinding version="1.2"/>
</jaxws:binding>

Do you guys know how to do this in the Java code (on the Port, on the SOAPBinding...)?

你们知道如何在 Java 代码中执行此操作吗(在端口上,在 SOAPBinding 上...)?

Thanks in advance for your help!

在此先感谢您的帮助!

EDIT----------------------

编辑 - - - - - - - - - - -

I'm still stuck with this problem... I tried to add the SOAPBinding annotation on the interface as suggested in one of the response below but it didn't work... I'm still searching for a way to manually configure my PortType / Binding / Bus to use Soap 1.2...

我仍然遇到这个问题......我试图按照下面的一个响应中的建议在界面上添加 SOAPBinding 注释,但它没有用......我仍在寻找一种方法来手动配置我的端口类型/绑定/总线使用 Soap 1.2 ...

Any ideas?

有任何想法吗?

EDIT----------------------

编辑 - - - - - - - - - - -

Problem solved! Actually I answered my own question: see below...

问题解决了!其实我回答了我自己的问题:见下文......

Thanks!

谢谢!

回答by reef

Ok I answer again to my own question to share the solution. With the help of the guys from the CXF mailing list I found a solution that works for me. There is actually 2 ways to solve the problem. Here is the explanation:

好的,我再次回答我自己的问题以分享解决方案。在 CXF 邮件列表中的人的帮助下,我找到了一个适合我的解决方案。实际上有2种方法可以解决这个问题。这是解释:

The problem came from the way I was building my CXF Service.

问题来自我构建 CXF 服务的方式。

The first solution is to specify the WSDL location at Service creation time:

第一种解决方案是在服务创建时指定 WSDL 位置:

// Create the service
Service service = Service.create(urlToWsdl, serviceQName);
// Access the port
return service.getPort(serviceQName, portTypeClass);

This solved the problem but I didn't want to have that link to the WSDL, so here is the second solution that gets rid of this link:

这解决了问题,但我不想拥有到 WSDL 的链接,所以这里是摆脱此链接的第二个解决方案:

// Create the service
Service service = Service.create(serviceQName);
// Add a Port to the service and specify the SOAP 1.2 binding
service.addPort(serviceQName, javax.xml.ws.soap.SOAPBinding.SOAP12HTTP_BINDING, wsUrl);
// Access the port
return service.getPort(serviceQName, portTypeClass);

In my project we decided to choose the second solution.

在我的项目中,我们决定选择第二种解决方案。

Hope this helps!

希望这可以帮助!

回答by Daniel Kulp

Easiest is probably to just stick an annotation on the interface of:

最简单的可能是在以下界面上粘贴注释:

@BindingType(SOAPBinding.SOAP12HTTP_BINDING)

回答by theMind

if you are using cxf client , you can use following way. Also it can bind more than one wsdl.

如果您使用的是 cxf 客户端,则可以使用以下方式。它也可以绑定多个 wsdl。

JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(WebServiceClass);
        BindingConfiguration config = new BindingConfiguration() {

    @Override
    public String getBindingId() {
            // TODO Auto-generated method stub
            return "http://www.w3.org/2003/05/soap/bindings/HTTP/";//SOAPVersion.SOAP_12.httpBindingId
    }
    };
    factory.setBindingConfig(config);

回答by reef

As suggested by Donal Fellows I answer to my own question ;)

正如 Donal Fellows 所建议的,我回答了我自己的问题;)

Actually the issue was linked to the Soap version the server can handle. On the client side I do not need to specify that I want to use Soap 1.2, it seems it's sufficient to have the PortType in the WSDL file configured to Soap 1.2. But on the server side I need to explicitly tell which Soap version I want. On the server side I still use the "Spring-mode" for CXF configuration thus I just added the following in the XML configuration file:

实际上,该问题与服务器可以处理的 Soap 版本有关。在客户端,我不需要指定我要使用 Soap 1.2,似乎将 WSDL 文件中的 PortType 配置为 Soap 1.2 就足够了。但是在服务器端,我需要明确说明我想要哪个 Soap 版本。在服务器端,我仍然使用“Spring-mode”进行 CXF 配置,因此我只是在 XML 配置文件中添加了以下内容:

<jaxws:binding>
    <soap:soapBinding version="1.2"/>
</jaxws:binding>

That's all folks! Thanks for your time and help!

这就是所有的人!感谢您的时间和帮助!

EDIT --------------------------------

编辑 - - - - - - - - - - - - - - - -

Actually this solution does not work now that we contact a server we do not manage.... We are still stuck with our problem here....

实际上,这个解决方案现在不起作用,因为我们联系了一个我们不管理的服务器......我们仍然在这里遇到我们的问题......

回答by Jim Smith

Old thread. I thought I'd post a solution that worked for me. In the cxf-beans.xml file, I changed the endpointName="tns:MR_ServerSoap12"from endpointName="tns:MR_ServerSoap". Note that the endpoint name will have its own name in your wsdl. Use that name.

旧线程。我以为我会发布一个对我有用的解决方案。在CXF-beans.xml的文件,我改变了endpointName="tns:MR_ServerSoap12"endpointName="tns:MR_ServerSoap"。请注意,端点名称将在您的 wsdl 中拥有自己的名称。使用那个名字。