如何使我的Web服务工作 [英] How to get my web service working

查看:52
本文介绍了如何使我的Web服务工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨 -



我有一个调用存储过程的Web方法。 sp单独运行时工作。现在将其移入方法我得到一个空引用异常,我不知道如何解决。我不熟悉使用服务,所以任何帮助都表示赞赏。我们的想法是通过web方法从sp中选择一个ID列表。调用web方法是在抛出错误时。



这是代码

Hi -

I have a web method calling a stored procedure. The sp works when run separately. Now moving that into the method I am getting a null reference exception which i'm not sure how to resolve. I'm not to familiar with working with service so any help is appreciated. The idea is to select a list of ID's from the sp via the web method. Invoking the web method is when the error is thrown.

Here is the code

<WebMethod()>
Public Function GetPTSID(term As String)
    Dim ptsid As List(Of String)

    Dim cs As String = ConfigurationManager.ConnectionStrings("PTS_EConnectionStringDEV").ConnectionString
    Using con As New SqlConnection(cs)

        Dim cmd As New SqlCommand("stpr_GetPTSIDs", con)
        cmd.CommandType = CommandType.StoredProcedure
        Dim parm As New SqlParameter("term", term)
        cmd.Parameters.Add(parm)
        con.Open()
        Dim reader As SqlDataReader = cmd.ExecuteReader()

        While reader.Read()
            ptsid.Add(reader("TAPV_TAPNUM"))
        End While
    End Using

    Return ptsid

End Function

推荐答案

用于保存List集合的变量是Nothing(null)。



当你宣布这样的时候:

The variable you're using to hold your List collection is Nothing (null).

When you declared it like this:
Dim ptsid As List(Of String)



你只说变量 ptsid CAN持有 List(Of String)。你实际上没有创建列表



改为


you only said that the variable ptsid CAN hold a List(Of String). You didn't actually create the List.

Change that to

Dim ptsid As New List(Of String)



你将创建列表。



如果您了解如何使用调试器,那么这个很容易找到。


and you'll create the list.

This one would be really easy to find if you understood how to use the debugger.


这篇关于如何使我的Web服务工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆