如何调用web服务的Javascript为Firefox 3.0 [英] How to call webservice in Javascript for Firefox 3.0
问题描述
我有一个问题用一个Firefox调用的.NET Web服务
客户。一个简单的例子就足够我。
I have a problem with calling .Net web services with a Firefox client. A simple example will be enough for me.
服务器端code是这样的:
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";
}
}
客户端的.html code:
Client side .html code:
Hello World Denemesi<br />
type="text" disabled="disabled" /></td>
value="Print" onclick="print()"> </td>
客户端的.js code:
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;
}
}
本网站服务适用于IE浏览器,但在Firefox不运行,因为
webservice.htc(行为文件)不用于Firefox的工作。我需要一个
JavaScript或类似的东西wihch我CANN来代替HTC
文件...
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...
推荐答案
如果您正计划消耗你的Web服务在NET,我会建议使用ScriptService,
客户端API是更简单,应该是工作在大多数浏览器,请参见下面的示例:
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;
}
}
}
客户端HTML code:
Client side html code:
Hello World Denemesi
<button onclick="test1()">print</button>
客户端的.js code:
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>
这篇关于如何调用web服务的Javascript为Firefox 3.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!