このように作成されたサービスがあります。
サービス.vb
_ Public Class UmbrellaService Inherits System.Web.Services.WebService IUmbrellaMobileService を実装
Function GetCustomers() As List(Of Customers) Implements IUmbrellaMobileService.GetCustomers
Try
Dim Cust As List(Of Customers) = New List(Of Customers)
Dim SQLSTR As String = ""
SQLSTR = "Select Companies.Code, Companies.Name FROM Companies WHERE ISCustomer = '1'"
Dim ErrorMessage As String = ""
ErrorMessage = UmbrellaDataManagementObj.OpenConnection(SQLServer, UmbrellaDatabase, UserCode, UserPassword)
If ErrorMessage <> "" Then
System.Diagnostics.EventLog.WriteEntry("Umbrella Mobile Service", ErrorMessage & vbNewLine & UmbrellaDataManagementObj.ConnectionString, EventLogEntryType.Error)
WebOperationContext.Current.OutgoingResponse.StatusCode = 501
WebOperationContext.Current.OutgoingResponse.StatusDescription = ErrorMessage
Return Nothing
Else
Dim CustomerDetails As DataSet
CustomerDetails = UmbrellaDataManagementObj.GetDataSQL(SQLSTR)
If Not CustomerDetails Is Nothing Then
CustomerDetails.DataSetName = "Companies"
CustomerDetails.Tables(0).TableName = "Companies"
Dim CustomerTable As DataTable
Dim CustomerRow As DataRow
If CustomerDetails.Tables.Count > 0 Then
CustomerTable = CustomerDetails.Tables(0)
If CustomerTable.Rows.Count > 0 Then
Dim i As Integer
For i = 0 To CustomerTable.Rows.Count - 1
CustomerRow = CustomerTable.Rows(i)
Dim CC As New Customers
CC.Code = CustomerRow.Item("Code")
CC.Name = CustomerRow.Item("Name")
Cust.Add(CC)
Next i
' Serialize the results as JSON
Dim serializer As DataContractJsonSerializer = New DataContractJsonSerializer(Cust.GetType())
Dim Stream As MemoryStream = New MemoryStream
serializer.WriteObject(Stream, Cust)
' Return the results serialized as JSON
Dim json As String = Encoding.Default.GetString(Stream.ToArray())
' Return json
Return Cust
UmbrellaDataManagementObj.CloseConnection()
WebOperationContext.Current.OutgoingResponse.StatusCode = 200
WebOperationContext.Current.OutgoingResponse.StatusDescription = "OK"
End If
End If
'Return Cust
Else
System.Diagnostics.EventLog.WriteEntry("Umbrella Mobile Service", UmbrellaDataManagementObj.ErrorMessage, EventLogEntryType.Error)
WebOperationContext.Current.OutgoingResponse.StatusCode = 501
WebOperationContext.Current.OutgoingResponse.StatusDescription = UmbrellaDataManagementObj.ErrorMessage
Cust = Nothing
Return Nothing
End If
End If
Catch ex As Exception
System.Diagnostics.EventLog.WriteEntry("Umbrella Mobile Service", ex.Message, EventLogEntryType.Error)
WebOperationContext.Current.OutgoingResponse.StatusCode = 501
WebOperationContext.Current.OutgoingResponse.StatusDescription = ex.Message
Return Nothing
End Try
Dispose()
End Function
インターフェイスは次のようになります。
<ServiceContract()> _
Public Interface IUmbrellaMobileService
<OperationContract()> _
<WebInvoke(Method:="GET", BodyStyle:=WebMessageBodyStyle.Bare, ResponseFormat:=WebMessageFormat.Json)> _
Function GetCustomers() As List(Of Customers)
End Interface
私のデータコントラクトは次のようになります:
<DataContract()> _
Public Class Customers
Dim CompanyName As String
Dim CompanyCode As String
<DataMember()> _
Public Property Name() As String
Get
Return CompanyName
End Get
Set(ByVal value As String)
CompanyName = value
End Set
End Property
<DataMember()> _
Public Property Code() As String
Get
Return CompanyCode
End Get
Set(ByVal value As String)
CompanyCode = value
End Set
End Property
End Class
ここで、アドレスhttp://agilesoft.dyndns.org/UmbrellaMobileService/GetCustomersを入力すると、次のように JSON 配列が返されます。
[{"コード":"001","名前":"虹"},{"コード":"009MAY","名前":"AMG AUDIO : HIRE ACC."}]
Devextreme アプリケーションでこの情報を表示しようとしています。これは私の dxview のコードです:
<div data-options="dxView : { name: 'Customer', title: 'Customer' } " >
<div data-options="dxContent : { targetPlaceholder: 'content' } " >
<div data-bind="dxList: { items: listItems }">
<div data-options="dxTemplate: { name: 'item' } ">
<div data-bind="text: Name"></div>
</div>
</div>
</div>
</div>
これはjsファイルのコードです:
UmbrellaMobile.Customer = function (params) {
var baseAddress = 'http://agilesoft.dyndns.org/UmbrellaMobileService/GetCustomers';
var listItems;
var viewModel = {
Customers: new DevExpress.data.CustomStore({
load: function () {
return $.ajax({
url: baseAddress,
crossOrigin: true,
jsonp: true,
type: 'GET',
data: '{}',
dataType: 'jsonp',
contentType: "application/json; charset=utf-8",
success: function (res) {
listItems: data;
console.log("success");
},
error: function (res) {
console.log("error");
}
});
}
})
};
return {
listItems: listItems,
viewModel: viewModel
};
};
このアプリを Firefox で実行すると、「表示するデータがありません」というメッセージが表示されます
コードをデバッグしようとしました。ブレークポイントを設定し、ヒントがないかコンソール ウィンドウを調べました。エラーは発生しません。ajax呼び出しは実行されないか、ヒットしないようです
情報を表示したいだけ
誰が問題が何であるかを理解するのを助けることができますか?