天天看点

Unmarshalling Error: 意外的元素的问题的解决

webservice方法中用cxf连接xfire,报错如下图

Unmarshalling Error: 意外的元素的问题的解决

代码如下

import javax.jws.WebService;
import javax.jws.WebMethod;
@WebService(name = "CommonWebService", targetNamespace = "http://service.*.*.com")
public interface CommonWebService
{
    @WebMethod
    public String addHouse(String softId, long applicationId, String city, String projectName);
}
           
import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;

public class CxfClientConnectXfire
{
	public static void main(String[] args)
	{
		test();
	}

	public static void test()
	{
		JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
		factory.setAddress("http://ip:port/*/services/CommonWebService");
		factory.setServiceClass(CommonWebService.class);

		CommonWebService client = (CommonWebService) factory.create();
		System.out.println("----cxf客户端,接口形式,连接xfire----");
		System.out.println(client.addHouse("*", 1, "aa", "bb"));
	}

}
           

出现问题后,打开wsdl

Unmarshalling Error: 意外的元素的问题的解决

在接口的方法声明上加入:@WebResult(name = "out", targetNamespace = "http://service.*.*.com")

问题解决!!!