1、使用Xfire客戶端調用webService接口時出現異常
Exception in thread "main" org.codehaus.xfire.XFireRuntimeException: Could not invoke service.. Nested exception is org.codehaus.xfire.fault.XFireFault: Server did not recognize the value of HTTP Header SOAPAction: .
org.codehaus.xfire.fault.XFireFault: Server did not recognize the value of HTTP Header SOAPAction: .
at org.codehaus.xfire.fault.Soap11FaultSerializer.readMessage(Soap11FaultSerializer.java:31)
xfire客戶端調用方式使用pojo方式,源碼如下
執行類
package com.digitalchina.chexingyi.test;
import org.codehaus.xfire.XFireFactory;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.service.binding.ObjectServiceFactory;
import com.digitalchina.app.trfvlt.api.IFsTraffic;
import com.digitalchina.chexingyi.api.IThirdPartyUserCarInfor;
public class Test {
private static Service srvcModel;
private static XFireProxyFactory factory;
static
{
srvcModel = new ObjectServiceFactory().create(IThirdPartyUserCarInfor.class);
factory = new XFireProxyFactory(XFireFactory.newInstance().getXFire());
}
private static String webserviceURL = "http://test.cx580.com:9000/WebService/OrderService/ThirdPartyUserCarInforService.asmx?WSDL";
/**
* @author chenxg
* @param args
* @throws Exception
*/
public static void main(String[] args) throws Exception {
String userName = "zhihui2015";
String userPwd = "DKFbyBNyu3/lPJ/YRBP3+g==";
String registerUserPhone = "13724865512";//手機號或者郵箱(車輛所有人)
String carNumber = "粵B4BB39";
String carCode = "284889";//車架號
String carDriver = "CA310233";//發動機號
String carOwner = "";//車主信息(姓名)
IThirdPartyUserCarInfor ws = (IThirdPartyUserCarInfor) factory.create(srvcModel, webserviceURL);
String response = ws.RegisterThirdUserCarInfor(userName, userPwd, registerUserPhone, carNumber, carCode, carDriver, carOwner);
System.out.println(response);
}
}
接口類IThirdPartyUserCarInfor
public interface IThirdPartyUserCarInfor {
String RegisterThirdUserCarInfor(String userName, String userPwd, String registerUserPhone, String carNumber, String carCode, String carDriver, String carOwner);
}
2、解決方法
在網上找了好多文章,似乎都是關於接口服務端的問題,但是我這裏是調用別人第三方的接口。一般都是java客戶端調用.net實現的webservice接口出現的問題,經過嘗試不同方法,不要使用pojo的方式去調用xfire的接口,而是採用myexlipse自動生成xfire的客戶端方式去實現,最後沒有出現該問題。
關於怎麼使用myeclipse自動生成xfire的webservice接口客戶端方式,下篇文章會去介紹。