微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PB调用WebService遇到的问题

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

经过过反复的调试,终于发现问题所在。我上传的参数是一个结构体数组,在给结构体赋值时,如果结构体的某一字段赋了null,上传到WebService后,整个对象(结构体)都会为null。找到了原因,问题迎刃而解!

另附PB调用WebService调试的方法

       将Vs.Net 的WebService启动调试,让它处于调试状态,并设好WebService的断点;再调试PB程序,只要PB调用的WebService方法在Vs.Net 中有断点,就会自动进入Vs.Net 的环境中查看参数的传递情况。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐