从jQuery调用Web服务 [英] Call web service from jQuery
问题描述
我正在尝试使用jQuery来使用我的Web服务,并且基本上只需要Web服务来调用所有功能.
I'm trying to use jQuery to consume my Web service and just basically need the web service to call functions that's all.
我在.NET中使用的代码是这样的:
The code I'm using in .NET is this:
[ServiceContract(Namespace = "http://Sinvise.Service/")]
public interface ISinvise
{
[OperationContract]
void Output(string value);
}
class SinviseService : ISinvise
{
second sec = new second();
public void Output(string value)
{
sec.message(value);
}
}
+
Uri baseAddr = new Uri("http://localhost:60185/Sinvise");
ServiceHost localHost = new ServiceHost(typeof(SinviseService), baseAddr);
try
{
Process.Start(baseAddr.AbsoluteUri);
localHost.AddServiceEndpoint(typeof(ISinvise), new WSHttpBinding(), "CalculatorService");
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
localHost.Description.Behaviors.Add(smb);
localHost.Open();
Console.WriteLine("Service initialized.");
Console.WriteLine("Press the ENTER key to terminate service.");
Console.ReadLine();
localHost.Close();
}
catch (CommunicationException ex)
{
Console.WriteLine("Oops! Exception: {0}", ex.Message);
localHost.Abort();
}
我怎样才能简单地调用Output
网络服务?
How would I be able to simply call the Output
web service?
谢谢
推荐答案
您可以使用 .get()
You can use an ajax request using .get()
由于浏览器的安全性限制,大多数"Ajax"请求都受相同的原始策略约束;该请求无法成功从其他域,子域或协议检索数据.脚本和JSONP请求不受相同的原始策略限制.
Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol. Script and JSONP requests are not subject to the same origin policy restrictions.
这篇关于从jQuery调用Web服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!