Tag: .net 3.5

字典不支持反序列化数组

更新: 我有以下代码,我尝试使用returned JSON数据,反序列化它,并将该数据的一部分返回给用户。 Class Item Public Property some_number() As Double Get Return m_some_number End Get Set(ByVal value As Double) m_some_number = value End Set End Property Private m_some_number As Double Public Property some_text() As String Get Return m_some_text End Get Set(ByVal value As String) m_some_text = value End Set End Property Private m_some_text As String […]

没有ASP.NET AJAX的JQuery / WCF:

当WCF配置得很好并且jQuery很好地构建其请求/理解响应时,我正在努力获得“神奇”的时刻。 我有服务: 这是由Rick Strahl建议的,以避免在Web.config中定义行为。 我的WCF服务接口位于另一个程序集中: namespace xxx.yyy.WCF.Data { [ServiceContract(Namespace = “yyyWCF”)] public interface IClientBroker { [OperationContract] [WebInvoke(Method=”POST”,BodyStyle=WebMessageBodyStyle.Wrapped,ResponseFormat=WebMessageFormat.Json)] IClient GetClientJson(int clientId); } } 具体的服务类是: namespace xxx.yyy.WCF.Data { [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] class ClientBroker : IClientBroker { public IClient GetClientJson(int clientId) { IClient client=new Client(); // gets and returns an IClient return client; } } } 我的IClient是一个entity framework类,因此适当地使用DataContract […]

问题从jQuery调用WCF服务库

我有一个通过我的ASPX站点公开的WCF服务库,如下所示 [System.ServiceModel.OperationContract] [System.ServiceModel.Web.WebInvoke( Method= “POST”, RequestFormat=System.ServiceModel.Web. WebMessageFormat .Json, ResponseFormat=System.ServiceModel.Web.WebMessageFormat .Json)] LogonResponse Logon(LogonRequest logonRequest); [System.Runtime.Serialization.DataContract] [ Serializable()] public class LogonRequest { [System.Runtime.Serialization.DataMember] public string EMailAddress; [System.Runtime.Serialization.DataMember] public string Password; } 在我的测试页面中,我可以通过MS Ajax调用: – . . . function clsLogonRequest(eMailAddress, password) { this .EMailAddress = eMailAddress; this .Password = password; } function login(eMailAddress, password) { var LogonRequest = […]

使用jquery将DataTable传递给Json

我正在尝试执行一个Web服务,该服务使用以下代码返回DataTable: $.ajax({ type: “POST”, url: url, data: data, contentType: “application/json; charset=utf-8”, dataType: “json”, success: function(msg) { //do things } }); 如果webservice返回一个类,那么它就可以工作,因此它与输入参数等无关。它只在web方法返回一个数据表时失败(数据表只有2列和2行用于我正在进行的测试)。 WebService类使用[ScriptService]属性进行修饰,因此我认为ASP.NET会自动将返回值序列化为JSON。 它似乎不适用于数据表。 我发现的唯一解决方案是返回一个字符串(一个手动JSON序列化对象),但这样做对我来说似乎不对。 我正在使用Visual Studio 2008和.Net 3.5

在尝试发布数据时,使用Jquery调用.Net webservice会造成祸患

当数据键没有要发送的数据时,以下代码正确执行,即数据:“{}”一个空的JSON对象,而webservice不带任何参数。 我想将一些数据发布到网络服务,但我遇到了麻烦。 当我尝试将其设置为数据时:“{‘name’:’Niall’,’surname’:’Smith’}”,我收到错误 {“Message”:”Invalid web service call, missing value for parameter: \u0027json\u0027.”,”StackTrace”:” at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary`2 parameters)\r\n at System.Web.Script.Services.RestHandler.InvokeMethod(HttpContext context, WebServiceMethodData methodData, IDictionary`2 rawParams)\r\n at System.Web.Script.Services.RestHandler.ExecuteWebServiceCall(HttpContext context, WebServiceMethodData methodData)”,”ExceptionType”:”System.InvalidOperationException”} Web服务未执行。 这是我的Jquery调用,将我的数据发布回服务器。 $.ajax({ type: “POST”, url: “/WebServices/BasketServices.asmx/AddItemToBasket”, data: “{‘name’:’niall’}”, // Is this Correct?? contentType: “application/json; charset=utf-8”, dataType: “json”, success: OnItemAddedSuccess }); […]

使用来自.NET服务的jQuery获取JSON数据:与ajax设置混淆

我刚刚花了六个小时试图把这个直接放在我脑海里,但我还没有成功。 我的本地机器上有一个HelloWorld .NET 3.5 Web服务。 根据需要进行设置 。 该服务返回自定义结构List 。 我正在尝试使用jQuery 1.4.4来使用它。 当我尝试执行文档所说的内容时,我总是从服务中获取XML响应,这会导致jQuery中的parseerror或者作为哑字符串传递给success函数。 也就是说,我结合了dataType并accepts (根据文档控制接收数据的处理方式),我得到了一个XML。 但是,当我从文档中做一些逻辑上不合适的事情时,我成功地获取了我的对象数组。 也就是说,当我忽略dataType并accepts ,并设置contentType: “application/json; charset=utf-8” ,它工作正常。 但是,根据文档, contentType控制发送到服务器的数据,而不是接收到的数据。 在代码中: $.ajax( { type: “GET”, url: “http://localhost:52624/Service1.asmx/HelloWorld”, dataType: “json”, //accepts can be anything, or it can be missing, doesn’t matter, only depends on dataType success: function(data, textStatus, jqXHR) {…}, error: function(jqXHR, textStatus, errorThrown) […]