だから私はいくつかの問題を抱えています。問題の目標は、Ajax を使用してユーザー コントロールから Web サービスを呼び出そうとすると、500 内部サーバー エラーが発生することです。
私のコードサンプルがあります:
Web サービス .CS
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class BudgetJson : System.Web.Services.WebService {
public BudgetJson ()
{
}
[WebMethod]
public static String GetRecordJson()
{
return " Hello Master, I'm Json Data ";
}
}
ユーザー コントロール (.Ascx) ファイル (Ajax 呼び出し)
$(document).ready(function () {
$.ajax({
type: "POST",
url: "BudgetJson.asmx",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg)
{
alert(msg);
}
});
});
したがって、ページが読み込まれてリクエストが送信されると、次のような応答が返されました。
soap:ReceiverSystem.Web.Services.Protocols.SoapException: サーバーは要求を処理できませんでした。---> System.Xml.XmlException: ルート レベルのデータが無効です。行 1、1 の位置。 System.Xml.XmlTextReaderImpl.Read() での ParseDocumentContent() System.Xml.XmlTextReader.Read() で System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read() で System.Xml.XmlReader.MoveToContent() System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.MoveToContent() で System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement() で System.Web.Services.Protocols.
メソッド名をURLに追加すると、次のようなエラーが発生しました:
不明な Web メソッド GetRecordJson。パラメーター名: methodName 説明: 現在の Web 要求の実行中に未処理の例外が発生しました。エラーの詳細とコード内のどこでエラーが発生したかについては、スタック トレースを確認してください。
例外の詳細: System.ArgumentException: 不明な Web メソッド GetRecordJson。パラメータ名: methodName
解決策はありますか?