背景:公司與某電訊廠商合作,電訊廠商提供了介面文檔,在文檔中規定了資料流是雙向的,電訊廠商和公司之間的通訊採用Web Service方式,雙方互為用戶端和伺服器端。這次遇到的問題,就是電訊廠商的用戶端調用我公司服務端的Web Service時出現的情況。需要特別說明的是:電訊廠商有幾十家夥伴,所以用戶端的代碼是不能因為某一家夥伴而修改的,各夥伴的WEB SERVICE開發環境也不相同,大部分都是用JAVA語言開發,而我公司是用VS2005開發的。
過程:
涉及的介面文檔部分如下:
使用者資料同步(syncUserData):
Index |
Parameter Name |
Req |
Type |
Size |
Description |
1 |
Mobile |
M |
String |
21 |
使用者號碼 |
2 |
SPID |
M |
String |
21 |
合作方標識 |
3 |
Service |
M |
String |
21 |
業務代碼 |
4 |
Action |
M |
Integer |
4 |
使用者操作 |
5 |
Time |
M |
String |
14 |
時間戳記 YYYYMMDDhhmmss |
6 |
Desc |
M |
String |
255 |
原因描述 |
7 |
Terminal |
M |
String |
4 |
終端類型 |
電訊廠商用戶端採用:JAVA JDK 1.5+AXIS實現的Web Service用戶端調用,並提供了具體的調試例子:
package smp.webservice.client;
import java.rmi.RemoteException;
import javax.xml.namespace.QName;
import javax.xml.rpc.ServiceException;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
public class ServiceClient ...{
public int syncUserData(String Mobile, String SPID, String Service, Integer Action, String Time, String Desc, String terminal, String serviceEndPoint)
throws Exception ...{
Object result=null;
try ...{
Call call = this.invokeFunction("syncUserData", serviceEndPoint);
result=call.invoke(new Object[] ...{ Mobile, SPID, Service, Action, Time, Desc, terminal });
} catch (Exception e) ...{
throw e;
}
try...{
return ((Integer)result).intValue();
}catch(Exception e)...{
return Integer.parseInt(((String)result));
}
}
public Call invokeFunction(String operationName, String serviceEndPoint)
throws ServiceException ...{
Service service = ServiceInstance.getInstance();
Call call = (Call) service.createCall();
call.setTargetEndpointAddress(serviceEndPoint);
call.setOperationName(new QName(operationName));
return call;
}
/** *//**
* test the client method
*/
public static void main(String[] args) ...{
ServiceClient sc = new ServiceClient();
String endPoint = "http://127.0.0.1/WebTest/Service.asmx";
try ...{
int i=sc.syncUserData("13312345678", "3735127", "834621", new Integer(8), "20080101120000", "desc","9",endPoint);
System.out.println("result: " + i);
} catch (Exception e) ...{
e.printStackTrace();
}
}
}
其中endPoint的值是用於調用我本地的.net開發的WEB服務地址。
我用asp.net中的C#語言產生了WEB