.ajax调用在.net中返回未定义?

.ajax调用在.net中返回未定义?,.net,json,mongodb,.net,Json,Mongodb,我正在尝试使用mongodb作为数据库来构建vb.net web应用程序。应用程序需要使用web服务并返回JSON字符串。作为剑道UI图表的数据源 我的web服务:- Imports MongoDB.Bson Imports MongoDB.Driver Imports MongoDB.Driver.Builders Imports System.Web.Services Imports System.Web.Services.Protocols

我正在尝试使用mongodb作为数据库来构建vb.net web应用程序。应用程序需要使用web服务并返回JSON字符串。作为剑道UI图表的数据源

我的web服务:-

    Imports MongoDB.Bson
    Imports MongoDB.Driver
    Imports MongoDB.Driver.Builders
    Imports System.Web.Services
    Imports System.Web.Services.Protocols
    Imports System.Web.Script.Services
    'Imports System.Web.Script.Serialization
    Imports System.ComponentModel
    Imports System.IO
    Imports AjaxControlToolkit

    ' To allow this Web Service to be called from script, using ASP.NET AJAX,'uncomment the following line.
    <System.Web.Script.Services.ScriptService()> _
    <System.Web.Services.WebService(Namespace:="http://tempuri.org/")> _
    <System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
    <Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class WebService_BufferFile
    Inherits System.Web.Services.WebService
    Dim connectionString As String = "mongodb://localhost"
    Dim client = New MongoClient(connectionString)
    <WebMethod()> _
    Public Function BufferFile_Power(ByVal UserId As Integer, ByVal DataBaseName As String, ByVal Collection As String, ByVal FileDate As DateTime, ByVal FileName As String) As String
    '<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=False)> _
    'runner = Mongo2Go.MongoDbRunner.Start()
    'runner.Import(strDatabase, strCollection, ImportFilePath, False)
    'MongoImportExport.Import("C:\MongoDB\bin\", 27017, strDatabase, strCollection, ImportFilePath, False)

    Dim ImportFilePath As String = "E:\SCADA\RAW\" & DataBaseName & "\" & Collection & "\" & Format(FileDate, "yyyy") & "\Buffer\" & FileName & ""
    If File.Exists(ImportFilePath) Then
        Dim ImportProcess As New Process()
        ImportProcess.StartInfo.UseShellExecute = True
        ImportProcess.StartInfo.CreateNoWindow = True
        ImportProcess.StartInfo.WorkingDirectory = "C:\MongoDB\bin"
        ImportProcess.StartInfo.FileName = "mongoimport.exe"
        ImportProcess.StartInfo.Arguments = " --db " & DataBaseName & " --collection " & Collection & "_" & Format(FileDate, "yyMMdd") & "_" & UserId & " --type csv --file " & ImportFilePath & " --headerline"
        ImportProcess.Start()
        ImportProcess.WaitForExit(1500)
        ImportProcess.Dispose()
    Else
        Return 0
        Exit Function
    End If
    Dim server = client.GetServer()
    Dim database = server.getDatabase(DataBaseName)
    Dim UserCollection = Collection & "_" & Format(FileDate, "yyMMdd") & "_" & UserId
    Dim Docs As MongoCursor = database.GetCollection(UserCollection).FindAll()
    Docs.SetSortOrder(SortBy.Ascending("timestamp"))
    Docs.SetFields(Fields.Include("timestamp", "converter_UL1", "converter_UL2", "converter_UL3", "converter_I1", "converter_I2", "converter_I3").Exclude("_id"))
    Docs.SetLimit(3000)
    Dim JsonString = Docs.ToJson
    If Docs.Count > 0 Then
        Docs.Database.DropCollection(UserCollection)
    End If
    'Dim jsonSearializer As New JavaScriptSerializer()
    'Return jsonSearializer.Serialize(JsonString)
    'Return 234
    Return JsonString

    End Function
End Class
导入MongoDB.Bson
导入MongoDB.Driver
导入MongoDB.Driver.Builders
导入System.Web.Services
导入System.Web.Services.Protocols
导入System.Web.Script.Services
'导入System.Web.Script.Serialization
导入System.ComponentModel
导入System.IO
导入AjaxControlToolkit
'要允许使用ASP.NET AJAX从脚本调用此Web服务,'请取消对以下行的注释。
_
_
_
_
公共类WebService\u缓冲文件
继承System.Web.Services.WebService
Dim connectionString作为字符串=”mongodb://localhost"
Dim客户端=新的MongoClient(connectionString)
_
公共函数BufferFile_Power(ByVal UserId作为整数,ByVal DataBaseName作为字符串,ByVal Collection作为字符串,ByVal FileDate作为DateTime,ByVal FileName作为字符串)作为字符串
' _
'runner=Mongo2Go.MongoDbRunner.Start()
'runner.Import(strDatabase、strCollection、ImportFilePath、False)
'MongoImportExport.Import(“C:\MongoDB\bin\”,27017,strDatabase,strCollection,ImportFilePath,False)
Dim ImportFilePath格式为String=“E:\SCADA\RAW\”&DataBaseName&“\”&Collection&“\”&Format(FileDate,“yyyy”)&“\Buffer\”&FileName&”
如果文件.Exists(ImportFilePath),则
作为新进程的Dim ImportProcess()
ImportProcess.StartInfo.UseShellExecute=True
ImportProcess.StartInfo.CreateNoWindow=True
ImportProcess.StartInfo.WorkingDirectory=“C:\MongoDB\bin”
ImportProcess.StartInfo.FileName=“mongoimport.exe”
ImportProcess.StartInfo.Arguments=“--db”&DataBaseName&“--collection”&collection&“&Format(FileDate,“yyMMdd”)&“&UX”&UserId&”--type csv--file”&ImportFilePath&“--headerline”
ImportProcess.Start()
ImportProcess.WaitForExit(1500)
ImportProcess.Dispose()文件
其他的
返回0
退出功能
如果结束
Dim server=client.GetServer()
Dim database=server.getDatabase(DataBaseName)
Dim UserCollection=Collection&“&”格式(FileDate,“yymmd”)&“&”UserId
Dim Docs As MongoCursor=database.GetCollection(UserCollection.FindAll())
Docs.SetSortOrder(按升序排序(“时间戳”))
Docs.SetFields(字段。包括(“时间戳”、“转换器\ UL1”、“转换器\ UL2”、“转换器\ UL3”、“转换器\ I1”、“转换器\ I2”、“转换器\ I3”)。排除(“\ id”))
文件设置限制(3000)
Dim JsonString=Docs.ToJson
如果Docs.Count>0,则
Docs.Database.DropCollection(UserCollection)
如果结束
'Dim jsonSearializer作为新的JavaScriptSerializer()
'返回jsonSearializer.Serialize(JsonString)
'返回234
返回JsonString
端函数
末级
HTML页面:-

<link href="CSS/kendo.common.min.css" rel="stylesheet" />
<link href="CSS/kendo.dataviz.min.css" rel="stylesheet" />
<link href="CSS/kendo.default.min.css" rel="stylesheet" />
<script type="text/javascript"> </script>
<script src="Scripts/jquery-1.7.1.min.js"></script>
<script src="Scripts/kendo.all.min.js"></script>
<table border="0" align="center">
    <tr>
        <td class="auto-style1" >
            <div id="BufferPowerChart" class="k-content">
            <div class="PowerChart-wrapper" style="margin: auto;">
                <div id="PowerChart"></div>
            </div>
                <script>
                    function createPowerChart() {
                        $.ajax(
                        {
                            type: 'POST',
                            url: '/WebService_BufferFile.asmx/BufferFile_Power',
                            contentType: 'application/json; charset=utf-8',
                            dataType: 'json',
                            data: '{"UserId":174,"DataBaseName":"ChitraDurga","Collection":"NSLHK-06","FileDate":"05/05/2013","FileName":"NSLHk-06_b130505_1819.txt"}',
                            async: false,
                            success: OnSuccess,
                            error: OnError
                        });

                        function OnSuccess(PowerChartData) {
                            alert(PowerChartData.d);
                            var PowerChartDataSource = JSON.parse(PowerChartData.d);
                            $("#PowerChart").kendoChart({
                                title: {
                                    text: "Power"
                                },
                                legend: {
                                    visible: true,
                                    position: "bottom"
                                },
                                dataSource: PowerChartDataSource,
                                series: [{
                                    type: "line",
                                    field: "converter_UL1",
                                    name: "converter_UL1"
                                }, {
                                    type: "line",
                                    field: "converter_UL2",
                                    name: "converter_UL2"
                                }, {
                                    type: "line",
                                    field: "converter_UL3",
                                    name: "converter_UL3"
                                }, {
                                    type: "line",
                                    field: "converter_I1",
                                    name: "converter_I1"
                                }, {
                                    type: "line",
                                    field: "converter_I2",
                                    name: "converter_I2"
                                }, {
                                    type: "line",
                                    field: "converter_I3",
                                    name: "converter_I3"
                                }],
                                categoryAxis: {
                                    field: "timestamp",
                                    labels: {
                                        rotation: -5
                                    },
                                    majorGridLines: {
                                        visible: true
                                    }
                                },
                                valueAxis: {
                                    max: 1500,
                                    line: {
                                        visible: true
                                    },
                                    majorUnit:100,
                                    minorGridLines: {
                                        visible: true
                                    }
                                },
                                tooltip: {
                                    visible: true,
                                    template: "#= series.name #: #= value #"
                                }
                            });
                        }
                        function OnError(msg) {
                            alert('Error = ' + msg.d);
                        }
                    }
                    $(document).ready(function () {
                        //debugger;
                        setTimeout(function () {
                            createPowerChart();
                        }, 500);
                    });
            </script>
            <style scoped>
                .PowerChart-wrapper, .PowerChart-wrapper .k-chart {
                    height: 520px; width:850px;
                }
            </style>
            </div>
        </td>
    </tr>        
</table>

函数createPowerChart(){
$.ajax(
{
键入:“POST”,
url:“/WebService\u BufferFile.asmx/BufferFile\u Power”,
contentType:'application/json;charset=utf-8',
数据类型:“json”,
数据:{“UserId”:174,“DataBaseName”:“ChitraDurga”,“Collection”:“NSLHK-06”,“FileDate”:“05/05/2013”,“FileName”:“NSLHK-06_b130505_1819.txt”},
async:false,
成功:一旦成功,
错误:OnError
});
函数OnSuccess(PowerChartData){
警报(PowerChartData.d);
var PowerChartDataSource=JSON.parse(PowerChartData.d);
$(“#PowerChart”)。肯多卡特({
标题:{
正文:“权力”
},
图例:{
可见:对,
位置:“底部”
},
数据源:PowerChartDataSource,
系列:[{
键入:“行”,
字段:“转换器_UL1”,
名称:“转换器_UL1”
}, {
键入:“行”,
字段:“转换器_UL2”,
名称:“转换器_UL2”
}, {
键入:“行”,
字段:“转换器_UL3”,
名称:“转换器_UL3”
}, {
键入:“行”,
字段:“转换器_I1”,
名称:“转换器_I1”
}, {
键入:“行”,
字段:“转换器_I2”,
名称:“转换器_I2”
}, {
键入:“行”,
字段:“转换器_I3”,
名称:“转换器_I3”
}],
类别:{
字段:“时间戳”,
标签:{
轮换:-5
},
主要生产线:{
可见:正确