VB Web服务调用错误未设置对象引用

时间:2014-03-11 23:35:46

标签: vb.net web-services rest

嘿所有我想弄清楚为什么我会收到以下错误:

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

我有什么可忘记的?

1 个答案:

答案 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)