Tag: wcf

Jquery:ajax调用工作和自动完成不与WCF一起工作

我正在使用jquery来弄清楚如何使用autocomplete 。 我有两个输入类型文本example和example2 。 我只是想知道为什么它适用于ajax调用示例文本框而不适用于example2文本框上的自动完成方法。 这是WCF服务接口: [ServiceContract] public interface IMyService { [WebInvoke(Method = “GET”, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = “getcompletions/q={q}&limit={limit}”)] List GetCompletions(string q, string limit); } 当我使用ajax调用它很好地工作: $(document).ready(function () { var url = “http://localhost.:62138/”; var data = null; /* //this webservice call works for UriTemplate = “getcompletions/{q}” $.ajax({ url: url + “MyService.svc/GetCompletions/” […]

通过ajax调用webservice方法

我有WCF服务方法: [WebInvoke(Method = “POST”, UriTemplate = “validateLogin”, ResponseFormat = WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Bare)] [OperationContract] bool validateLogin(Login objLogin); 我通过我的phonegap代码ajax调用此方法: var parameters = { “EmailID”: EmailID, “Password”: Password }; $.ajax({ url: “http://localhost:95/MobileEcomm/Service1.svc/validateLogin”, data: JSON.stringify(parameters), contentType: “text/xml;charset=utf-8”, dataType: “json”, headers: { SOAPAction: ” }, type: ‘POST’, processdata: false, cache: false, success: function (Data) { alert(“asdsad”); }, error: function (response) { var […]

jQuery .ajax调用从不调用方法

在这篇SOpost中,我学会了如何从AJAX调用中获取返回值: function CallIsDataReady(input) { $.ajax({ url: “http://www.blah.com/services/TestsService.svc/IsDataReady”, type: “GET”, contentType: “application/json; charset=utf-8”, data: input, dataType: “json”, success: function (data) { if (!data) { setTimeout(function (inputInner) { CallIsDataReady(inputInner); }, 1000); } else { //Continue as data is ready callUpdateGrid(input); } } }); } $(document).ready(function () { var input = { requestGUID: “” }; CallIsDataReady(input); }); 此函数调用其Web服务,确实返回true。 […]

.JQuery .ajax如何用返回值调用WCF方法?

我已经能够使用.ajax调用WCF方法。 如何调用返回值的方法? 我需要调用此方法来查看数据是否已就绪,如果没有等待一秒钟。 WCF方法是: [OperationContract] [WebGet] public bool IsDataReady(string requestGUID) { if (Global.publicDataDictionary.Keys.Contains(requestGUID)) return true; else return false; } 到目前为止我的JavaScript是: $(document).ready(function() { var input = {requestGUID:””}; console.log(input); $.ajax({ url: “http://www.blah.com/services/TestsService.svc/IsDataReady”, type: “GET”, contentType: “application/json; charset=utf-8”, data: input, dataType: “json”, success: function(data) { } }); EDIT2:我将第二个ajax调用分解为一个方法但我的日志记录显示对第二个Web服务的调用从未传递requestGUID。 我不能使用相同的输入变量吗? var guid = “”; // var input = ‘{“SbiId”:”‘ […]

从JQuery将复杂对象上载到WCF REST服务

我正在尝试将复杂对象上传到我的WCF REST服务。 我这样做是因为它似乎是同时将Stream类型对象和其他参数上传到端点的最简单方法。 服务: [OperationContract] [WebInvoke(Method = “POST”, BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, UriTemplate = “Upload”)] public string upload(UploadObject uploadObject) { return uploadObject.stream.ToString() + ” ” + uploadObject.guid; } [DataContract] public class UploadObject { [DataMember] public Stream stream { get; set; } [DataMember] public string guid { get; set; } } […]

Jquery无法从WCF REST服务获得响应

我已经开发了WCFrest服务并将其部署在可以通过浏览器访问的链接上,因为它的操作是“GET”。 我想使用jQuery获取该数据。 我尽力让WCf使用jQuery获得响应但是徒劳无功。 我也试过$ .Ajax和’jsonp’没有运气。 谁能帮我? 该url是: http : //www.lonestarus.com/AndroidApp/AndroidLocation.svc/RestService/getLatestLocation 您可以通过在浏览器中粘贴url来检查该url响应。

这里有什么问题让IE9可以做CORS Ajax调用,但IE8和FireFox不能?

我通过jQuery 向位于不同域的WCF服务发出POST请求。 它按预期适用于IE9: i)我发出请求, ii)登录对话框弹出窗口, iii)我登录并调用服务。 但是使用IE8和FireFox时 , 不会出现LogIn对话框 ,请求失败。 问题 :为什么它在IE9上进行基于CORS的ajax POST调用没有任何问题,而IE8和Fire-Fox没有? 请参阅以下其他详细信息 : 我有一个WCF RESTful服务,它位于IIS 7.5上的站点上 IIS上的身份validation设置为启用BASIC AUTHENTICATION 。 WCF服务安全模式在web.config中设置为: “ “ 我的web.config也有: 如何使用JavaScript进行调用: $.support.cors = true; // I make CORS enabled request = { Foo: “Alice”, Bar : “Sharma”, }; $.ajax( { type: ‘POST’, url: “foo.bar.co/myService”, contentType: ‘application/json’, data: JSON.stringify(request), success: function […]

jsonp调用WCF返回错误

背景: 我创建了一个运行良好的WCF服务(.NET 3.5),由于跨域限制(该服务与包含javascript的网页位于不同的服务器上),因此需要使用JavaScript进行服务。 ,标准肥皂贴不起作用。 我更改了一些配置,根据微软博客文章向该方法添加了一个WebInvoke属性,并使该服务与GET一起工作,并确认该方法通过soapUI测试工作。 我试图在JSFiddle上建立一个例子,但因为这是一个内联网服务,我显然无法让它工作。 这是我的SVC.cs文件中的方法:(我在尝试解决这个问题时对配置文件进行了一些代码更改和更改) // On the interface that defines the contract [OperationContract] [WebGet] string Post(string questionid, string answervalue); // In my actual service file code behine. public string Post(string questionid, string answervalue) { Guid dataid = _dataProvider.Post(questionid, answervalue); _dataProvider.Log(retval.ToString()); return dataid.ToString(); } 现在如果我只输入URL,我会得到GUID的字符串表示,代表该值。 http://localhost/WebPostSvc.svc/json/Post?questionid=207&answervalue=207009 returns: “04bb6445-b1af-4214-8f8b-cf66bb15467f” 这是我想要开始工作的JavaScript: // string functions to […]

完成WCF实现图片

我已经看过很多例子,甚至以前在一些WCF代码上工作过,也许还没有完全理解它。 既然我正在尝试自己实现它,我似乎无法让它工作所以我正在寻找一些提示! 这是我的情况: 好 – 我可以构建服务库并将其托管在服务应用程序或IIS7中,这两者都给我成功的结果,因为我可以通过在浏览器中输入.svc文件的位置来查看服务。 坏 – 我需要通过javascript连接到服务,但通过json连接到localhost给了我“没有传输”,或者如果我尝试通过jsonp连接到我的托管服务器给我’成功’,但有未定义的响应(应该是一个你好世界的回应..) 这是我在服务上的配置文件: 这是我的JS for json: $.ajax({ url: “http://10.8.8.53/Schools/SchoolsService.svc/TestSchoolVal1”, dataType: “json”, timeout: 10000, data: “4”, type: “POST”, success: function (data, textStatus, jqXHR) { }, error: function (jqXHR, textStatus, errorThrown) { }, complete: function (jqXHR, textStatus) { } }); jsonp代码是相同的只有jsonp而不是json和jsonpcallback函数定义。 有什么建议? 我需要同时获得localhost和我的IIS7! 我也尝试在visual studio中包含外部引用,它生成了更多web.config – 但我想通过javascript访问svn,而不是后端代码! 更多信息:服务名称空间是SchoolsWCF,类是Service1,服务文件是SchoolsService.svc,方法是TestSchoolVal1,它接受一个int参数,localhost托管应用程序是一个Windows控制台应用程序。

Sharepoint 2010 wcf服务。 用jquery调用方法

我在sharepoint应用程序中使用了wcf服务。 但是当我尝试从jquery调用方法时,它总是失败。 我用这样的字符串测试了服务: ttp://localhost/_vti_bin/webservices/wcfservice.svc/**mex** 并有正常的反应。 WCF测试客户端也有响应。 但在我的JavaScript代码中,我总是收到错误。 为什么? 我做错了什么? $.ajax({ url: “/_vti_bin/webservices/wcfservice.svc/HelloWorld”, dataType: ‘json’, contentType: “application/json”, success: function (res) { alert(“good answer”); }, error: function (xhr) { alert(“error”); return; } }); 浏览器响应: 服务代码: [BasicHttpBindingServiceMetadataExchangeEndpoint] [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)] [ServiceContract] public class WCFService { // To test this service, use the Visual Studio WCF Test client // […]