从DynamicPopulateExtender调用时,“Web服务调用失败:0”

时间:2011-09-22 12:28:36

标签: c# asp.net ajaxcontroltoolkit

我从ASP DynamicPopulateExtender调用Web服务,但似乎得到“Web服务调用失败:0”错误,好像它没有找到Web服务。还有其他原因导致错误代码0适用吗?

这是.aspx文件:

    <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
    </asp:ToolkitScriptManager>

     <h1>Stock Updates</h1>
        <asp:Panel ID="upExtenderContent" runat="server" CssClass="dynamicPopulate_Normal">
            Stock file import has STARTED please wait....<br /><br />
            <asp:Image ID="imgLoading" runat="server" ImageUrl="~/admin/adminimages/uploading.gif" />
        </asp:Panel>

        <asp:DynamicPopulateExtender ID="dpeAjaxImport" runat="server" 
            TargetControlID="upExtenderContent" 
            BehaviorID="dp1" 
            ClearContentsDuringUpdate="false"  
            ServiceMethod="importStock" 
            ServicePath="importFile.asmx"
            ContextKey="none"
            PopulateTriggerControlID="btnImport">
        </asp:DynamicPopulateExtender>
        <br />
        <asp:Button ID="btnImport" runat="server" OnClick="importFile" Text="Upload" />

        <script type="text/javascript">
            function uploadData(value) {

                var behavior = $find('dp1');

                if (behavior) {
                    behavior.populate(value);
                }
            }

            Sys.Application.add_load(function () { uploadData('c:/Ben_Saved_Small.csv'); });


        </script>

服务所在的importFile.asmx文件与上面的.aspx文件位于同一目录中,因此应该很容易找到:

<%@ WebService Language="C#" CodeBehind="importFile.asmx.cs" Class="GG.co.uk.admin.importFile" %>

此文件标题引用以下文件内容:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Script.Services;
using System.Web.Services;
using System.Text;
using System.IO;
using GG.co.uk.App_Code;
using GGDAL;

namespace GG.co.uk.admin
{
/// <summary>
/// Summary description for importFile
/// </summary>

[WebService(Namespace = "http://GG.co.uk.admin/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
[ScriptService]

// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class importFile : System.Web.Services.WebService
{

    [WebMethod]
    public static string importStock(string contextKey)
    {
        string returnResponse="";

        //Load data into website database
        try
        {

            //Read and process files

        }
        catch (Exception ex)
        {
            returnResponse = returnResponse + "<span style=\"color:red;font-weight:bold;\">Uh-Oh! " + ex.Message + "</span> : " + contextKey;
        }

        return returnResponse + "<br />";
    }
}
}

关于这一点的灯光真的很有帮助。
感谢。

1 个答案:

答案 0 :(得分:-1)

删除

ContextKey = “无”

in

DynamicPopulateExtender标记

并尝试