编程语言
首页 > 编程语言> > java使用cxf写的webservices,PB进行调用

java使用cxf写的webservices,PB进行调用

作者:互联网

package com.study.webservice;

import com.oracle.xmlns.internal.webservices.jaxws_databinding.XmlWebMethod;
import org.apache.cxf.Bus;
import org.apache.cxf.BusFactory;
import org.apache.cxf.frontend.ServerFactoryBean;
import org.apache.cxf.transport.servlet.CXFNonSpringServlet;
import org.apache.cxf.wsdl.service.factory.MethodNameSoapActionServiceConfiguration;

import javax.servlet.ServletConfig;

/**
* CXFNonSpringServlet这个类的名字还真是直接,这样就能直接使用servlet部署在tomcat上面了
* PB调用java 的webservices,终于找到原因了。不容易啊!!!!!!!!!!!!!!!!!
* http://localhost:8080/ws/hi?wsdl
*/
public class CxfService extends CXFNonSpringServlet {

protected void loadBus(ServletConfig sc) {
super.loadBus(sc);
Bus b=getBus();
BusFactory.setDefaultBus(b);
CXFtestWebservice hi = new CXFtestWebservice();//实现类
ServerFactoryBean sfb = new ServerFactoryBean(); //server工厂
//当时发现生成wsdl文件中的soapAction是空值,导致PB 调用不成功,下面这句话就是获取soapAction的,把这个加上,PB就能掉通了
sfb.getServiceFactory().getConfigurations().add(new MethodNameSoapActionServiceConfiguration());
sfb.setServiceClass(Cxftest.class);// 接口类
sfb.setAddress("/hi"); //服务请求路径
sfb.setServiceBean(hi);
sfb.create();
System.out.println(new XmlWebMethod().action().toString());
}

/**
* PB代码:
* 首先生成代理文件,然后编写下面代码进行调用
* String ls_url
* SoapConnection conn
* cxftestport ln_soap
* long ll_ret
* tns__sayHello lstr_sayhello
*
*
*
* lstr_sayhello.arg0 = '真的是不容易啊'
* ls_url = "http://localhost:8080/ws/hi?wsdl"
*
* conn = create SoapConnection
* conn.createinstance(ln_soap,"cxftestport",ls_url)
* ln_soap.sayhello(lstr_sayhello)
* messagebox('',string(ll_ret))
*/

}

标签:java,PB,webservices,cxf,org,apache,import,sfb
来源: https://www.cnblogs.com/jsname/p/16248197.html