Search code examples
.netajaxweb-servicesasp.net-ajaxasmx

MicrosoftAjax.js, SOAP Web Services, and static HTML


What is the proper way to call a ASMX Web Service with MicrosoftAjax.js if your just including the JavaScript in static HTML?

What I have so far:

<html>
<head>
    <title>Testing</title>
    <script type="text/javascript" src="scripts/MicrosoftAjax.js"></script>
    <script type="text/javascript">
        function testCallSoap() {
            // in here I want to call the default HelloWorld() method
            // it is located at ~/MyTestService.asmx
        }
    </script>
</head>

<body>
    <div>
        <span onclick="testCallSoap();">test</span><br />
    </div>
</body>
</html>

Solution

  • I've honestly never called a webservice without a script manager, but:

    In your webservice, you need to make sure that your WebService class uses the [ScriptService] attribute. Then you can include this js file: MyService.asmx/js.

    [ScriptService]
    public class MyService : WebService
    {
        [WebMethod]
        public string Foo()
        {
             return "bar";
        }
    }
    

    This will make it work with JSON... See this article: Link

    Not really a complete answer, but I hope it gets you moving in the right direction.