How to call webservice in Javascript for Firefox 3.0

后端 未结 2 1983
Happy的楠姐
Happy的楠姐 2021-01-28 02:52

I have a problem with calling .Net web services with a Firefox client. A simple example will be enough for me.

Server side code is like this:

[WebService         


        
相关标签:
2条回答
  • 2021-01-28 03:25

    If you are planning to consume your web service in NET, I would suggests using ScriptService, The client API is easier and should be working on most browsers, see below for a sample:

    namespace XXX.Services 
    {  
        [System.Web.Script.Services.ScriptService()]
        [WebService(Namespace = "http://tempuri.org/")] 
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
        [ToolboxItem(false)] 
        public class Service1 : System.Web.Services.WebService 
        { 
            [WebMethod] public string HelloWorld() 
            { 
                return "Hello World"; 
            } 
    
            [WebMethod] public string Greet(string name) 
            { 
                return "Hello " + name; 
            } 
        }
    }
    

    Client side html code:

    Hello World Denemesi
    <button onclick="test1()">print</button>
    

    Client side .js code:

    <script>
        function test1(){
             XXX.Services.HelloWorld(function(result){
                alert(result);//do something with the result
             });
    
             XXX.Services.Greet("John Cane",function(result){
                alert(result);
             });
        }
    </script>
    
    0 讨论(0)
  • 2021-01-28 03:31

    You could use the jQuery ajax calls, they make calling web services easy. See here: http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/

    0 讨论(0)
提交回复
热议问题