Results 1 to 2 of 2

Thread: Problem when call spring.net webservice from JQuery with POST method.

  1. #1
    Join Date
    Apr 2012
    Posts
    2

    Default Problem when call spring.net webservice from JQuery with POST method.

    I got a problem when call spring.net web service from JQuery with POST method.
    Here is the WebService code:
    Code:
    namespace SprintWS.WS
    {
        public interface  ITestWS
        {
            string GetMessage();
            string GetMessage2(string title, string content);
        }
        public class TestWS : ITestWS
        {
            private string message;
            public string Message
            {
                set { message = value; }
            }
    
            public string GetMessage()
            {
                return this.message;
            }
            public string GetMessage2( string title, string content)
            {
                return title + ":" +  content;
            }
        }
    }
    And it is configured to TestService.asmx

    If I call it in this way, it works well:
    Code:
        function TestWebService2()
        {
            //TestService.GetMessage2("t", "c");
            //alert("abc");
            $.ajax({
                //type: "POST",
                url: "TestService.asmx/GetMessage2?title=123&content=abc",
                //contentType: "application/json",
                //data: "{title:123,content:ccc}",
                //dataType: "xml",
                success: TestSuccess2,
                error: TestError
            });
    
        }
        function TestSuccess2(result)
        {
            alert(result.text);
        }
        function TestError2()
        {
        }
    And this also works:
    Code:
        function TestWebService()
        {
            //alert("abc");
            $.ajax({
                type: "POST",
                url: "TestService.asmx/GetMessage",
                //contentType: "application/json",
                data: "{}",
                //dataType: "xml",
                success: TestSuccess,
                error: TestError
            });
    
        }
        function TestSuccess(result)
        {
            alert(result.text);
        }
        function TestError( error)
        {
        }
    But when I call method with parameters, like GetMessage2 with POST method. Like this:
    Code:
            $.ajax({
                type: "POST",
                url: "TestService.asmx/GetMessage2?title=123&content=abc",
                //contentType: "application/json",
                data: {title:123,content:ccc},
                //dataType: "xml",
                success: TestSuccess2,
                error: TestError
            });
    Problem occurs.
    I got http response like this:
    Code:
    System.InvalidOperationException: Missing Parameter: title。
       在 System.Web.Services.Protocols.ValueCollectionParameterReader.Read(NameValueCollection collection)
       在 System.Web.Services.Protocols.HtmlFormParameterReader.Read(HttpRequest request)
       在 System.Web.Services.Protocols.HttpServerProtocol.ReadParameters()
       在 System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()
    Does any one knows how to solve this problem?
    Thanks, adun.
    Last edited by Steve Bohlen; 04-21-2012 at 12:02 PM. Reason: reformatting for code legibility

  2. #2
    Join Date
    Aug 2012
    Posts
    5

    Default

    I don't had this problem while calling Ajax enabled WCF service from JQuery.
    My first initiative here is to explain what Insanity is. Once you get the feel for it the customer insanity reviews will make more sense.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •