测试结果
后台代码
![
![
楼下的我先帮你占个位,楼下正解。
我看你这个很奇怪啊!用cxf发布的话,不都是在接口上打@webservice的注解么,
我给你看一下我的例子,你再看看!
----------------------------------------------接口的代码----------------------------------------
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import com.pccw.webservice.area.po.Area;
/**
@version 1.0
*/
@WebService(targetNamespace = "http://webservice.pccw.com/",
serviceName = "AreaWebService",
name = "AreaServiceSoap", portName = "AreaServiceSoap")
public interface AreaInterface {
//如果不想让某个方法发布为服务,可以将exclude设置成true
@WebMethod(operationName="queryAreaByParentid",exclude=false)
//查询区域,接收area对象(存储了查询区域条件信息),返回List
public List queryArea(@WebParam(name="area") Area area) throws Exception;
}
----------------------------接口实现-----------------------------------------
import java.util.List;
import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;
import com.pccw.webservice.area.dao.AreaDao;
import com.pccw.webservice.area.dao.AreaDaoImpl;
import com.pccw.webservice.area.po.Area;
/**
@version 1.0
*/
public class AreaInterfaceImpl implements AreaInterface {
// dao接口
private AreaDao areaDao = new AreaDaoImpl();
public List queryArea(Area area) throws Exception {
// 调用dao接口查询数据库得到List
List list = areaDao.queryArea(area.getParentid(),
area.getStart(), area.getEnd());
// 向客户端响应List
return list;
}
}
-----------------------------------------发布服务-------------------------------------
public class AreaServer {
public static void main(String[] args) {
//下边是cxf的JaxWsServerFactoryBean发布服务方式
//创建服务工厂bean,用于发布服务
JaxWsServerFactoryBean jaxWsServerFactoryBean = new JaxWsServerFactoryBean();
//指定服务地址
jaxWsServerFactoryBean.setAddress("http://127.0.0.1:12345/area");
jaxWsServerFactoryBean.setServiceClass(AreaInterface.class);
jaxWsServerFactoryBean.setServiceBean(new AreaInterfaceImpl());
//创建服务
jaxWsServerFactoryBean.create();
}
}
3年前的问题今天也遇到了 并且解决了 我决定把坑填上
这个问题在CXF官方论坛有人问过 回复如下
The specs all have that xml processing instruction thing as being optional,
mostly because it's completely redundant with SOAP/HTTP. With HTTP, the
content type already tells us that it's XML as well as the Charset. Thus,
that line is completely redundant and just a wast of bandwidth. SOAP tools
should not be requiring it.
In anycase, you CAN force CXF to output it. If you set a property of:
"org.apache.cxf.stax.force-start-document" to "true"
on the endpoint/client, it will out output that line.
URL
http://cxf.547215.n5.nabble.com/Tag-lt-Xml-version-quot-1-0-quot-encoding-quot-utf-8-quot-gt-in-the-response-td4439475.html
我测试过了 确实没问题
"org.apache.cxf.stax.force-start-document" to "true"