Tag: wcf

从jQuery调用Web服务

我正在尝试使用jQuery来使用我的Web服务,并且基本上需要Web服务来调用所有function。 我在.NET中使用的代码是这样的: [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 […]

AJAX文件上传到WCF服务的工作示例

我正在寻找一个将数据流式传输到WCF服务的ajax调用示例。 我总是收到一个错误。 任何帮助赞赏,甚至链接到博客与解决方案。 这是我的WCF服务类 [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)] public class Images : IImages { string IImages.UploadImage(string fileKey, Stream imageStream) { using (var fileStream = File.Create(@”Images\” + fileKey)) { imageStream.CopyTo(fileStream); } return “done”; } } 我的合同是 [OperationContract(Name = “UploadImage”)] [WebInvoke(UriTemplate = “?file_key={fileKey}”, Method = “POST”, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] string UploadImage(string fileKey, Stream imageStream); 我有web.config流绑定 […]

什么是服务参考的正确url?

我有两个项目,一个是WCF服务,它在文本框中说出文本/句子。 public class Service1 : IService1 { public string RunTts(string text) { using (SpeechSynthesizer synth = new SpeechSynthesizer()) { // Configure the audio output. synth.SetOutputToDefaultAudioDevice(); synth.Speak(text); return “”; } } } 然后我在第二个项目的_Layout.cshtml页面中用ajax调用它,它是asp.net mvc。 function ttsFunction() { serviceUrl = “Service1.svc/RunTts”; $.ajax({ type: “POST”, url: serviceUrl, data: ‘{“text”: “‘ + $(‘#speak’).val() + ‘”}’, contentType: “text/xml; charset=utf-8”, dataType: […]

IE9 XmlHttpRequest返回12019错误而不是HTTP / 417响应代码

我对客户端的WCF服务的ajax请求有一些error handling, self.remove = function (dep, processingResult) { var data = { “id”: dep }; $.ajax({ url: ‘my.svc/remove’, type: ‘POST’, contentType: ‘application/json’, dataType: “json”, cache: false, data: JSON.stringify(data), complete: function (e, xhr, settings) { var message = self.getMessage(e.status); switch (e.status) { case 200: processingResult(); break; case 417: console.log(e.statusText); radalert(message + e.statusText, null, null, “417”); break; […]

使用jquery将文件上传到wcf

我有一个页面,其中有一个文件上传控件。 我想使用jquery(不发布表单)将此文件上传控件的内容发送到WCF服务,这可能吗?

测试/构建MSDN文章“带填充的JSON(AJAX)”

更新3 var local = ‘http://localhost:1163/CustomerService.svc/getcustomer?method=?’; var dev = ‘http://yourserver.com/CustomerService.svc/GetCustomer?method=?’; $.getJSON(dev, function (customer) { alert(customer.Address); alert(customer.Name); }); 如果我在远程域上运行http://yourserver.com/CustomerService.svc/getcustomer?method=foo’我会获得访问被拒绝错误并且如果我运行http://yourserver.com/CustomerService.svc/getcustomer?method=?’ 我收到此错误(见下文),我在您的示例页面中拥有您所拥有的内容。 似乎“method = foo”“get access denied”和“method =?” 抛出此错误:URI: “http://yourserver.com/CustomerService.svc.svc/GetCustomer?method=jsonp1290197214042” UPDATE3 UPDATE2 我测试了两种不同的场景: 1) 与localhost一起正常工作 $.getJSON(‘http://localhost:1163/service.svc/getcustomer?method=?’, function (customer) { alert(customer.Address); alert(customer.Name); }); 2) 不适用于跨域 $.getJSON(‘http://yourserver.com/CustomerService.svc/getcustomer?method=?’, function (customer) { alert(customer.Address); alert(customer.Name); }); 我收到此错误: 消息:预期’;’ 行:1个字符:11个代码:0 URI: http://yourserver.com/CustomerService.svc/GetCustomer?method=jsonp1290183992345 UPDATE2 UPDATE1 当我在浏览器http://yourserver.com/CustomerService.svc/getcustomer中运行服务时,我得到弹出窗口要求我保存或保存文件,所以我将文件保存到浏览器,然后在记事本,我看到数据,所以它返回我的jsonp。 […]

jQuery .ajax()405(不允许的方法)/跨域

我已经看到了很多关于此的问题,但是我找不到代码中缺少的东西。 我正在实现CORS因为我不想使用JSONP 。 我知道这是一个preflighted请求 ,我想我正在添加正确的headers 。 错误是网站似乎不喜欢我的WCF ,每次我做一个请求时,即使我有Access-Control-Allow-Methods标头,也会调用一个OPTION方法。 我只想用一个contentType: “application/json”,对我的WCF进行POST调用contentType: “application/json”, WCF是自托管的,Web应用程序位于IIS 7.5 。 Chrome显示的内容: 小提琴手表现出什么 合同 Function LookUpPerson(person As Person) _ As List(Of Person) 的app.config JavaScript的 $.ajax({ url: “http://192.168.0.61:8282/Project.Services.Person/LookUpPerson”, type: “POST”, contentType: “application/json”, crossDomain: true, dataType: “json”, data: { person: JSON.stringify(person) }, success: function (data) { // doing something }, error: function (error) { […]

将对象数组发送到WCF

在我的应用程序中,我想使用jQuery和Ajax保存数据。我有一个WCF服务。 我想使用ajax保存一个对象列表。我已尝试使用以下代码,但它无法正常工作。 jquery代码: var listOfObjects=new Array(); //creating list of objects for(var i=0;i<5;i++) { var MyEntity=new Object(); MyEntity.TestId =i; MyEntity.TestId =i+"testName"; listOfObjects.push(MyEntity); } //Saving info $.ajax({ type: "POST", async: false, data: JSON.stringify(listOfObjects), url: "../ServiceLayer/myService.svc/SaveResults", contentType: "application/json; charset=utf-8", dataType: "json", success: function () { alert("success"); }, error: function () { alert("Error"); } }); WCF: [WebInvoke(Method = “POST”, […]

创建一个WCF服务从jQuery.AJAX()接受JSON数据

我一直在寻找几个小时并尝试不同的方法来实现这一目标。 我已经尝试了很多关于stackoverflow的文章,或者我太愚蠢了,无法让事情发生,或者我有一些独特而奇怪的配置让我无法体验到快乐。 我创建了本教程概述的WCF服务: http://www.codeproject.com/Articles/97204/Implementing-a-Basic-Hello-World-WCF-Service 它是超级基础的并且有一个方法,我想要它做的就是允许我使用json使用jQuery.AJAX()。 我把它托管在IIS中,它的工作原理。 我可以毫无问题地访问WSDL。 我尝试使用以下代码使用它: $.ajax({ dataType: ‘json’, type: ‘POST’, contentType: “application/json”, url: “//localhost:546/HelloWorldService.svc/GetMessage”, data: { name: “Joe” } }).done(function(msg){ console.log(msg); $(“#result”).append(msg); }); 我总是得到错误。 根据我的尝试,我得到500错误,402错误,错误内容错误…所有错误。 我尝试过以下文章中的解决方案。 它们包括让我更改web.config端点(我知道我必须更改它们但我迄今为止没有尝试过添加JSON端点的工作)来添加像 [WebInvoke(Method = “POST”, UriTemplate = “json/PostSalesOrderData”, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)] 到界面。 以下是我看过的一些文章,并试图粉碎我的解决方案,使其工作没有太大的成功。 Phonegap Android上的Javascript JSON和WCF webservice HTTP / 1.1 415无法处理消息,因为内容类型为’application […]

跨域调用WCF服务

我有一个WCF服务,这是一个我要调用的方法: [OperationContract] [WebInvoke(Method = “POST”, BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)] double?[] GetPoints(string tourname); 我通过WCF测试客户端检查,它工作正常 所以我需要从html页面调用这个方法。 它应该适用于跨域的其他计算机。 我用jQuery 1-6-2.min.js写了一些东西: var varType; var varUrl; var varData; var varContentType; var varDataType; var varProcessData; function CallService() { alert(“CallService”); $.ajax({ type : varType, //GET or POST or PUT or DELETE verb url : varUrl, // Location of the service […]