Skip to content Skip to sidebar Skip to footer

How To Call Webservice In Javascript For Firefox 3.0

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(Namespace = 'http://tempur

Solution 1:

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>

Solution 2:

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/


Post a Comment for "How To Call Webservice In Javascript For Firefox 3.0"