Pregunta

he configurar este ejemplo de servicio web para investigar el origen de mi error:

    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; }
    }

}

Se basa en un ejemplo aquí

Así que he tratado de buscar un resultado aquí:

http://localhost:57109/webservice/WebService1.asmx/AjaxGet?id=li1234

Y consigo el resultado,

 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)

Por lo tanto, supongo que es web.config ¿verdad? Por lo tanto, la configuración del implemento sugerido (PS, también he creado un servicio web HTTP POST y funciona muy bien)

A partir de 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>
¿Fue útil?

Solución

Resulta que este problema fue el resultado de una cierta clase de problemas / nombre-espacio pobre código re-factoring y de mi parte.

Además, se permiten señalar que mantenerse alejado formar HTTPGet cuando se utiliza jQuery webservices es una buena idea, volver a la información que he leído aquí

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top