2011-07-15 15 views
0

I次のWebサービスがあります。Webサービスがnullを返すのはなぜですか?

<%@ WebService Language="VB" Class="WebService" %> 

Imports System.Web 
Imports System.Web.Script.Services 
Imports System.Web.Services 

' To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
<System.Web.Script.Services.ScriptService()> _ 
<WebService(Namespace:="http://tempuri.org/")> _ 
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _ 
Public Class WebService 
    Inherits System.Web.Services.WebService 

    Public Class Person 
     Public FirstName As String 
     Public LastName As String 

     Public Sub New(ByVal m_FirstName As String, ByVal m_LastName As String) 
     End Sub 
    End Class 

    <ScriptMethod(ResponseFormat:=ResponseFormat.Json)> _ 
    <WebMethod()> _ 
    Public Function GetPersons() As List(Of Person) 
     Dim lst As List(Of Person) = New List(Of Person) 

     lst.Add(New Person("firstname_1", "surname_1")) 
     lst.Add(New Person("firstname_2", "surname_2")) 

     Return lst 
    End Function 
End Class 

しかし、それは戻っている:

{"d":[{"FirstName":null,"LastName":null},{"FirstName":null,"LastName":null}]} 

それは返すべきである:

{"d":[{"FirstName":"firstname_1","LastName":"surname_1"},{"FirstName":"firstname_2","LastName":"surname_2"}]} 

私が間違っているのは何を?

答えて

2

コンストラクタ内のFirstNameとLastNameは決して忘れないでください。その値はnullのままです。 あなたのコンストラクタに以下を追加します。

FirstName = m_FirstName 
LastName = m_LastName 
+0

それでした!ありがとう。 – oshirowanen

0

私のVBは少し錆びですが、私はあなたのPersonクラスでは、姓と名のプロパティが表示されません。私は変数だけを見ます。 (先に言及されていなかった割り当てと一緒に)

関連する問題