これまでWebサービス(ASMX)をHTMLページから直接呼び出すことはありませんでした。私は自分のWebサービスにアクセスしようとすると、私はエラーメッセージを取得しておいてください。HTMLファイルからWebServiceにアクセスできない(内部500エラー)
石鹸:ReceiverSystem.Web.Services.Protocols.SoapException: サーバーは要求を処理できませんでした。 ---> System.Xml.XmlException: ルートレベルのデータが無効です。 1行目、1位...
ターゲットフレームワーク4.5のVisual Studio 2015を使用しています。私はこれが500の内部エラーであることを知っています。つまり、サーバーの問題です。
HTMLコード:
<!DOCTYPE html>
<html>
<head>
<title>Testing</title>
\t <meta charset="utf-8" />
<script type="text/javascript" src="Scripts/jquery-2.2.4.js"></script>
</head>
<body>
<form>
<div id="todaysLoad"></div>
</form>
<script type="text/javascript">
$(document).ready(function() {
\t getTotals();
\t });
\t function getTotals() {
\t $.ajax({
type: "POST",
\t url: "Services/worker.asmx?HelloWorld",
\t data: "{}",
\t contentType: "application/json; charset=utf-8",
\t dataType: "jsonp",
\t success: function (data) {
\t $("#todaysLoad").html(data.d);
\t },
\t error: function (error) {
\t $("#todaysLoad").html(error.responseText);
\t }
\t });
\t }
</script>
</body>
</html>
WebServiceのコード:
using System.Web.Script.Services;
using System.Web.Services;
namespace MyApp.Services
{
/// <summary>The Worker WebService will act as a mediator between database and client</summary>
[WebService(Namespace = "http://tempuri.org/")]
[ScriptService]
public class worker : System.Web.Services.WebService
{
[WebMethod (EnableSession = true)]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet = false)]
public string HelloWorld()
{
return "Today is Tuesday";
}
}
}
のWeb.Configコード:
<?xml version="1.0" encoding="utf-8"?>
<!--
For more information on how to configure your ASP.NET application, please visit
http://go.microsoft.com/fwlink/?LinkId=169433
-->
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5.2" />
<httpRuntime targetFramework="4.5.2" />
<pages>
<controls>
<add tagPrefix="ajaxToolkit" assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" />
</controls>
</pages>
</system.web>
<system.web.extensions>
<scripting>
<webServices>
<jsonSerialization maxJsonLength="2147483647"></jsonSerialization>
</webServices>
</scripting>
</system.web.extensions>
<system.codedom>
<compilers>
<compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
<compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\"Web\" /optionInfer+" />
</compilers>
</system.codedom>
</configuration>
私は正常にWebServiceのURLをコピーして貼り付けることができ、私のブラウザでそれを参照します。私はHelloWorld()メソッドを呼び出すことさえできます。 HTMLページからWebServiceを呼び出そうとするとアクセスできません。
私は自分のソリューションにAJAX Control Toolkit(NuGet)をインストールしました。
アイデア?それとも、私は行方不明のものがありますか?
あなたはデータなしでそれを送信しようとしたことがありますか? –
はい、私は実際に 'data:" "'を使ってみましたが、まだ運がありません –
ちょっと速いアップデートです。 Visual Studio 2015でまったく新しいASP.NET WebFormsプロジェクトを作成し、JSON、jQuery、AJAX NuGetパッケージをソリューションにインポートしました。 WebServiceを追加し、ASPX WebフォームページからJavaScriptで簡単なAJAX呼び出しを作成しました。結果、私はまだSOAP例外エラーが発生しています。 –