【问题标题】:A call error on a web method using ajax platform... Unable to connect to the remote server?使用 ajax 平台的 Web 方法调用错误...无法连接到远程服务器?
【发布时间】:2011-04-19 04:37:46
【问题描述】:

以下方法曾经有效,但现在我收到此错误: 错误:Sys.Net.WebServiceFailedException:服务器方法失败并出现以下错误:System.Net.WebException-- 无法连接到远程服务器 我该如何解决?

function CallMe() {

    // call server side method
    PageMethods.GetData(function (result) {
        DcSet("lblUsdRub", result.UsdRub);
        DcSet("lblEurRub", result.EurRub);
        DcSet("lblMicex", result.Micex);
        DcSet("lblUrals", result.Urals);
        DcSet("lblUsdEur", result.UsdEur);
        DcSet("lblUsdTur", result.UsdTur);
        DcSet("lblNasdaq", result.Nasdaq);
        DcSet("lblImkb100", result.Imkb100);
    });
 }
 function DcSet(labelName, value) {

         document.getElementById(labelName).innerText = value.toFixed(3);

 }



(function () {
 var status = true;
 var fetchService = function () {
     if (status) {
         CallMe();
         status = false;

     }
     setTimeout(fetchService, 300000); //Every Five Minutes, Update Data 300000
     status = true;
 }
 addLoadEvent(fetchService);
// window.onload = fetchService;
 } ());

function addLoadEvent(func) {
    var oldonload = window.onload;
    if (typeof window.onload != 'function') {
        window.onload = func;
    } else {
        window.onload = function () {
            if (oldonload) {
                oldonload();
            }
            func();
        }
    }
}

aspx.cs 文件 使用系统; 使用 System.Collections.Generic; 使用 System.Linq; 使用 System.Web; 使用 System.Web.UI; 使用 System.Web.UI.WebControls; 使用 System.Web.Services; 使用 System.Web.Script.Services;

public partial class Index : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    [WebMethod]
    [ScriptMethod(ResponseFormat = ResponseFormat.Json)]
    public static OnlineData GetData()
    {
        return ExternalManager.GetOnlineData();
    }
}

aspx 文件

     <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
     <meta name="description" content="">
     <meta name="keywords" content=""> 

    <link rel="stylesheet" type="text/css" href="/c/main.css">
    <script src="/c/main.js" type="text/javascript"></script>

    <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico">

</head>
<body>
<script src="/c/Currency.js" type="text/javascript" ></script>
    <form id="form1" runat="server">
       <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true"  >

     </asp:ScriptManager>
    <div id="Content">
        <div class="nobg">

            <div id="Top">
                <div class="left">
                    <a href="index.aspx"><img src="/i/xxxx.gif" alt="xxxx" /></a>
                </div>

                <div class="right">

【问题讨论】:

    标签: c# asp.net web-services asp.net-ajax asmx


    【解决方案1】:

    鉴于您遇到了 .NET 异常,听起来 AJAX 调用可以毫无问题地访问您的 WebMethod - 听起来 ExternalManager.GetOnlineData(); 失败了。

    我建议您尝试在一个可以轻松调试的简单控制台应用程序中调用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-04
      • 2013-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-06-21
      相关资源
      最近更新 更多