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

发布于 2024-10-03 10:25:52 字数 579 浏览 0 评论 0原文

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

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

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

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

预先感谢您的帮助!

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

我仍然被这个问题困扰...... 我尝试按照下面的响应之一的建议在接口上添加 SOAPBinding 注释,但它不起作用...... 我仍在寻找一种方法来手动配置我的 PortType / Binding / Bus 以使用 Soap 1.2...

有什么想法吗?

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

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

谢谢!

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

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:

<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...)?

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...

Any ideas?

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

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

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

向日葵 2024-10-10 10:25:52

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

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

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

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

这解决了问题,但我不想将该链接添加到 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);

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

希望这有帮助!

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:

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

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

// 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:

// 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!

是伱的 2024-10-10 10:25:52

最简单的可能是在界面上添加注释:

@BindingType(SOAPBinding.SOAP12HTTP_BINDING)

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

@BindingType(SOAPBinding.SOAP12HTTP_BINDING)
百思不得你姐 2024-10-10 10:25:52

如果您使用的是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);

if you are using cxf client , you can use following way. Also it can bind more than one 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);
望她远 2024-10-10 10:25:52

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

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

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

这就是全部!
感谢您的时间和帮助!

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

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

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

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:

<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....

听风念你 2024-10-10 10:25:52

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文