问题
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...
回答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>
回答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/
来源:https://stackoverflow.com/questions/1571430/how-to-call-webservice-in-javascript-for-firefox-3-0