httpget returns system.indexoutofrangeExceptionを使用したC#.NET Webサービス
-
30-09-2019 - |
質問
エラーのソースを調査するために、このサンプルWebサービスをセットアップしました。
namespace userControlPanel.webservice
{
/// <summary>
/// Summary description for WebService1
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 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 WebService1 : System.Web.Services.WebService
{
[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public OutputData1 AjaxGetMore(InputData1 input)
{
return new OutputData1()
{
id = input.id,
message = "it's work!",
myInt = input.myInt + 1
};
}
}
public class OutputData1
{
public string id { get; set; }
public string message { get; set; }
public int myInt { get; set; }
}
public class InputData1
{
public string id { get; set; }
public int myInt { get; set; }
}
}
ここの例に基づいています
それで、私はここで結果を取得しようとしました:
http://localhost:57109/webservice/WebService1.asmx/AjaxGet?id=li1234
そして、私は結果を得る、
System.IndexOutOfRangeException: Index was outside the bounds of the array
at System.Web.Services.Protocols.HttpServerType..ctor(Type type)
at System.Web.Services.Protocols.HttpServerProtocol.Initialize()
at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing)
それで、私はそれがweb.configだと思いますよね?だから私は提案されたセットアップを実装しています(PS、私はまたhttp-postウェブサービスを作成しました、そしてそれはうまく機能します)
web.configから:
<webServices>
<protocols>
<add name="HttpPost"/>
<add name="HttpPostLocalhost"/>
<add name="HttpGet"/>
</protocols>
</webServices>
<httpHandlers>
<add verb="*" path="*.asmx" type="System.Web.Script.Services.ScriptHandlerFactory" validate="false"/>
</httpHandlers>
</system.web>
解決
この問題は、私の側のいくつかのコードの再因果関係とクラス/名前空間の問題のいくつかの結果であることが判明しました。
また、jquery webservicesを使用するときにhttpgetを形成することは良いアイデアであること、私が読んだ再情報であることに注意してください。 ここ
所属していません StackOverflow