嘿所有我想弄清楚为什么我会收到以下错误:
Object reference not set to an instance of an object.
代码第2行:
1. Dim HTPCws As HTPCWS.ServiceVB
2. Dim returned As String = HTPCws.DisplayMessageVB(what2send)
当我知道 what2send 确实有值发送....
Web服务代码是:
<WebMethod()> Public Function DisplayMessageVB(ByVal beingSent As String) As String
_strfromws = beingSent
Return "DONE"
End Function
我有什么可忘记的?
答案 0 :(得分:2)
HTPCws
尚未实例化。将代码更改为:
Dim HTPCws = New HTPCWS.ServiceVB()
Dim returned As String = HTPCws.DisplayMessageVB(what2send)
Dim HTPCws As HTPCWS.ServiceVB
声明一个变量,但不为它指定一个对象。命名也有点令人困惑。更好:
Dim service = New HTPCWS.ServiceVB()
Dim returned As String = service.DisplayMessageVB(what2send)