PB调用WebService遇到的问题
今天用PB调用WebService时,遇到了十分不解的问题,我WebService中的方法都使用单元测试验证过的,但用PB调用时,方法中的参数上传到WebService始终是null。(报的异常:System.NullReferenceException: Object reference not set to an instance of an object)我调用WebService的代码为:
if
dw_1.rowcount()
=
0
then
return
cashcarteinfo cartelist[]
cartelist = dw_1. object .data
cashcarteiteminfo carteitemlist[]
datastore ldst_carteitem
ldst_carteitem = create datastore
ldst_carteitem.dataobject = ' d_carteitem '
ldst_carteitem.settransobject( sqlca)
ldst_carteitem.retrieve( idt_uptime)
carteitemlist = ldst_carteitem. object .data
destroy ldst_carteitem
SoapConnection conn
cashservice cashweb
long rVal
conn = create SoapConnection
rVal = Conn.CreateInstance(cashweb, " cashservice " , " http://localhost/WebService/Service.asmx " )
try
string ls = space( 500 )
long stationid
stationid = 1
if cashweb.uploadcarte( cartelist, carteitemlist, stationid, ref ls) = true then
Messagebox( '' , ' succes ' )
else
Messagebox( ' fail ' ,ls)
end if
catch ( SoapException e )
messagebox ( " Error " , " Cannot invoke Web service~r~n " + e.getmessage( ) ) // error handling
end try
destroy cashweb
destroy conn
cashcarteinfo cartelist[]
cartelist = dw_1. object .data
cashcarteiteminfo carteitemlist[]
datastore ldst_carteitem
ldst_carteitem = create datastore
ldst_carteitem.dataobject = ' d_carteitem '
ldst_carteitem.settransobject( sqlca)
ldst_carteitem.retrieve( idt_uptime)
carteitemlist = ldst_carteitem. object .data
destroy ldst_carteitem
SoapConnection conn
cashservice cashweb
long rVal
conn = create SoapConnection
rVal = Conn.CreateInstance(cashweb, " cashservice " , " http://localhost/WebService/Service.asmx " )
try
string ls = space( 500 )
long stationid
stationid = 1
if cashweb.uploadcarte( cartelist, carteitemlist, stationid, ref ls) = true then
Messagebox( '' , ' succes ' )
else
Messagebox( ' fail ' ,ls)
end if
catch ( SoapException e )
messagebox ( " Error " , " Cannot invoke Web service~r~n " + e.getmessage( ) ) // error handling
end try
destroy cashweb
destroy conn
经过过反复的调试,终于发现问题所在。我上传的参数是一个结构体数组,在给结构体赋值时,如果结构体的某一字段赋了null,上传到WebService后,整个对象(结构体)都会为null。找到了原因,问题迎刃而解!
另附PB调用WebService调试的方法:
将Vs.Net 的WebService启动调试,让它处于调试状态,并设好WebService的断点;再调试PB程序,只要PB调用的WebService方法在Vs.Net 中有断点,就会自动进入Vs.Net 的环境中查看参数的传递情况。