我已经设置了此示例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 Web服务是一个好主意,我阅读的重新信息是一个好主意 这里

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top