最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
JAVA+AXIS客户端调用Asp.net Web Service过程中遇到的问题及解决方法
时间:2008-06-03 编辑:简简单单 来源:一聚教程网
背景:公司与某运营商合作,运营商提供了接口文档,在文档中规定了数据流是双向的,运营商和公司之间的通讯采用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
相关文章
- asp.net 利用Socket,http协议使服务器和客户端的交互方式 01-12
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18
- .Net反向代理组件Yarp用法介绍 10-10