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://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class Service1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello World";
}
}

Client side .html code:

Hello World Denemesi<br />
type="text" disabled="disabled" /></td> 
value="Print"           onclick="print()"> </td>

Client side .js code:

var callObject;
function init(){
service.useService( "Service1.asmx?WSDL","Service");
callObject = service.createCallOptions();
callObject.async = false;

}
function print(){
callObject.funcName = "HelloWorld";
var oResult = service.Service.callService(callObject );
if( !oResult.error )
{
edtHelloWorld.value = oResult.value;
}
}

This web service works on IE but doesn’t run at firefox because
webservice.htc (behaviour file) doesn’t work for firefox. I need a
javascript or something like that wihch I cann use instead of htc
file…

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 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>

Method 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/


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x