XFire 是 CXF的前身,已经停止更新多年,如非必要,请勿浪费时间。

CXF服务端

示例

  1. import javax.jws.WebParam;
  2. import javax.jws.WebService;
  3. @WebService
  4. public interface WsTest {
  5. String do(@WebParam(targetNamespace= "http://com.dzero.ws/")String something);
  6. }

注意

入参的注解 @WebParam(targetNamespace= "http://com.dzero.ws/") 必须添加,如果不添加该注解以及其命名空间,XFire客户端调用时会报如下相关错误:

  1. org.codehaus.xfire.fault.XFireFault: Unmarshalling Error: unexpected element (uri:"http://com.dzero.ws/", local:"arg0"). Expected elements are <{}arg0>

targetNamespace 的具体值可在wsdl的xml页面内容中找到(一般为package的倒叙)

XFire客户端

正常调用

  1. import java.net.MalformedURLException;
  2. import java.net.URL;
  3. import org.codehaus.xfire.client.Client;
  4. public class XfireClient {
  5. public static void main(String[] args) throws MalformedURLException, Exception {
  6. String urlStr="http://localhost:8080/CxfWSServer/webservice/WsTest?wsdl";
  7. Client client = new Client(new URL(urlStr));
  8. Object[] results = client.invoke("do", new Object[] { " shopping" });
  9. System.out.println(results[0]);
  10. }
  11. }

添加Http头信息

  1. import java.net.MalformedURLException;
  2. import java.net.URL;
  3. import org.codehaus.xfire.client.Client;
  4. import org.codehaus.xfire.transport.http.CommonsHttpMessageSender;
  5. public class XfireClient {
  6. public static void main(String[] args) throws MalformedURLException, Exception {
  7. String urlStr="http://localhost:8080/CxfWSServer/webservice/WsTest?wsdl";
  8. Client client = new Client(new URL(urlStr));
  9. Map m = new HashMap();
  10. m.put("userName", "dzero");
  11. client.setProperty(CommonsHttpMessageSender.HTTP_HEADERS, m);
  12. Object[] results = client.invoke("do", new Object[] { " shopping" });
  13. System.out.println(results[0]);
  14. }
  15. }