Tag: rest

解析PayPal REST信用卡交易响应(JSON)

我通过C#ASP.NET 4.5框架网站使用最新版本的PayPal REST API进行PayPal和信用卡交易。 事务在沙箱中完美运行,响应显示与事务关联的所有数据。 我想要做的是使用标签以更友好的方式显示该信息。 如何将JSON响应解析为标签或文本框? 这是显示不友好响应的当前代码。 try { APIContext apiContext = Configuration.GetAPIContext(); Payment createdPayment = pymnt.Create(apiContext); CurrContext.Items.Add(“ResponseJson”, JObject.Parse(createdPayment.ConvertToJson()).ToString(Formatting.Indented)); } catch (PayPal.Exception.PayPalException ex) { if (ex.InnerException is PayPal.Exception.ConnectionException) { Label4.Text = (((PayPal.Exception.ConnectionException)ex.InnerException).Response); } else { Label4.Text = (ex.Message); } CurrContext.Items.Add(“Error”, ex.Message); } CurrContext.Items.Add(“RequestJson”, JObject.Parse(pymnt.ConvertToJson()).ToString(Formatting.Indented));

Route属性中的正则表达式 – RESTful API ASP.NET Web API

我在Route属性中遇到了正则表达式的问题。 我想创建RESTful API,您可以在其中指定URL中的开始日期和结束日期以过滤结果。 我到现在所做的是: [HttpGet] [Route(“date/{startDate:datetime:regex(\\d{4}-\\d{2}-\\d{2})}/{*endDate:datetime:regex(\\d{4}-\\d{2}-\\d{2})}”)] [Route(“date/{startDate:datetime:regex(\\d{4}/\\d{2}/\\d{2})}/{*endDate:datetime:regex(\\d{4}/\\d{2}/\\d{2})}”)] public IEnumerable GetRecommendationByDate(DateTime startDate, DateTime? endDate) { var output = db.Recommendations .Where(r => r.IsPublished == true && r.CreatedDate.CompareTo(startDate) > 0 && r.CreatedDate.CompareTo(endDate.HasValue ? endDate.Value : DateTime.Now) r.LastModified) .ToList(); return output; } 它不是我想要的,因为第二个参数应该是可空的。 当我只通过开始日期时,我得到404.使用斜杠格式也不起作用。 我究竟做错了什么? 我以为*意味着参数可以为空… ===编辑=== 我要匹配的url都是: https:// localhost:post / api / recommendations / date / 10/07/2013 / […]

WCF Rest服务接收对象为null

我有WCFrest服务,期望对象作为输入。 [WebInvoke(Method = “POST”, UriTemplate = “SaveItem”, ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)] [OperationContract] public string SaveItem(Item item) { string retValue; using (var business = new ItemBusiness()) { retValue = business.SaveItem(item).ToString(); } return retValue; } 项目类如下所示。 [DataContract] public class Item { [DataMember] public string UserId { get; set; } [DataMember] public string […]

用于Azure移动服务(REST)的实时连接身份validation令牌

我有一个简单的Windows窗体应用程序来尝试Live Connect和Azure移动服务。 不是Windows 8现代应用程序。 我正在尝试使用Live Connect的一些示例代码,并且能够使登录部分正常工作。 最后,我在登录后获得了access_token。 在同一Windows窗体应用程序的移动服务端,我正在尝试使用REST登录。 但是,我希望获得“401 Unauthorized”响应,因为“身份validation令牌的签名格式错误或由其他密钥签名” JWT好像有两个’。’ 在令牌中。 SWT似乎有’/’,’+’和’=’ 我需要进行转换吗? 有没有办法配置Live Connect,以便返回的身份validation令牌是JWT(或移动服务所期望的)? 我在Live Connect和Mobile Services上都检查了客户机密码,它们是正确的。

我们如何为WebHttpBinding WCF REST服务实现会话管理?

我一直在使用webHttpBinding会话模式开发WCF REST服务。但是我总是得到这个错误“ 合同需要会话,但绑定’WebHttpBinding’不支持它或者没有正确配置以支持它。 ”可以任何一个人告诉我这是什么原因?

在单个HTTPWebRequest中上载多个文件

我创建了一个接受两件事的服务: 1)称为“类型”的身体参数。 2)要上传的csv文件。 我在服务器端读这两样东西是这样的: //Read body params string type = HttpContext.Current.Request.Form[“type”]; //read uploaded csv file Stream csvStream = HttpContext.Current.Request.Files[0].InputStream; 我怎么能测试这个,我用Fiddler来测试这个,但我一次只能发送一件事(无论是类型还是文件),因为两者都是不同的内容类型,我如何使用内容类型multipart / form-data和application / x-www-form-urlencoded同时进行。 即使我使用此代码 public static void PostDataCSV() { //open the sample csv file byte[] fileToSend = File.ReadAllBytes(@”C:\SampleData.csv”); string url = “http://localhost/upload.xml”; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = “POST”; request.ContentType = “multipart/form-data”; request.ContentLength = […]

为RESTful WCF配置SSL绑定。 怎么样?

我当前的配置如下: 当我为我的网站配置了http 和 https绑定时,这种方法有效。 我通过https连接到服务,一切都很好。 现在我想完全删除IIS上的http绑定。 我开始得到这样的错误: 找不到与绑定WebHttpBinding的端点的方案http匹配的基址。 注册的基地址方案是[https]。 [InvalidOperationException:找不到与绑定WebHttpBinding的端点的scheme http匹配的基址。 注册的基地址方案是[https]。] System.ServiceModel.ServiceHostBase.MakeAbsoluteUri(Uri relativeOrAbsoluteUri,Binding binding,UriSchemeKeyedCollection baseAddresses)+16582113 System.ServiceModel.Description.ConfigLoader.ConfigureEndpointAddress(ServiceEndpointElement serviceEndpointElement,ServiceHostBase host,ServiceEndpoint endpoint)+117 System.ServiceModel.Description.ConfigLoader.ConfigureEndpoint(StandardEndpointElement standardEndpointElement,ServiceEndpointElement serviceEndpointElement,ContextInformation context,ServiceHostBase host,ServiceDescription description,ServiceEndpoint&endpoint,Boolean omitSettingEndpointAddress)+937 System.ServiceModel.Description.ConfigLoader.LookupEndpoint(ServiceEndpointElement serviceEndpointElement,ContextInformation context,ServiceHostBase host,ServiceDescription description,Boolean omitSettingEndpointAddress)+8728167 System.ServiceModel.Web.WebServiceHost.AddAutomaticWebHttpBindingEndpoints(ServiceHost host,IDictionary`2 implementedContracts,String multipleContractsErrorMessage,String standardEndpointKind)+982 System.ServiceModel.Web.WebServiceHost.OnOpening()+311 System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)+612 System.ServiceModel.HostingManager.ActivateService(String normalizedVirtualPath)+255 System.ServiceModel.HostingManager.EnsureServiceAvailable(String normalizedVirtualPath)+1172 [ServiceActivationException:由于编译期间发生exception,无法激活服务’/ DEMO / mobile’。 exception消息是:找不到与绑定WebHttpBinding的端点的scheme http匹配的基址。 注册的基地址方案是[https] ..] System.Runtime.AsyncResult.End(IAsyncResult result)+901424 […]

我可以自动为REST WCF服务生成服务引用吗?

我可以看到SOAP WCF over REST(json)wcf的唯一参数是,一旦我的服务被创建,我就可以在visual studio中添加一个引用,我可以为我和一个客户端类添加一个强类型类的负载可以通过我所有的网络方式调用。 据我所知,它甚至设置了web.config。 但是当我公开REST(json)服务时,我仍然得到一个WSDL。 所以我想知道还有办法自动构建我的引用吗?

使用RestSharp发布数据时序列化对象

我最近开始使用RestSharp来使用使用XML的REST服务。 它使得从XML反序列化对象变得无关紧要。 但我的问题是,在回发到服务时重新排序的最佳方法是什么? 我应该使用LINQ-to-XML进行重新序列化吗? 我尝试使用Serializeable属性和SerializeToXml实用程序函数,但是当我这样做时,似乎打破了RestSharp执行的反序列化。

重新附加实体图并检测集合更改

我首先使用实体​​框架代码并通过WCF REST HTTP接口公开northwind数据库。 我没有公开OrderDetails表(订单商品),因为创建订单然后通过另一个服务分别添加每个必需的OrderDetail是没有意义的。 在我看来,它需要是一个成功或失败的primefaces事务。 因此,我在传递给客户端时包含Order.OrderDetails集合,并假设在创建或更新订单时我将获得一个。 然而,问题似乎是在重新附加Order实体以进行更新时检测OrderDetails集合的更改。 订单本身可以设置为已修改以更新这些属性,但这不会级联到OrderDetail项目。 所以我可以手动完成并设置更新的修改后的问题,但问题在于弄清楚哪些是最初更新的。 将新的OrderDetail设置为modified会在尝试保存时导致错误。 我读了一条建议,将新集合项的Id设置为0,并在服务器中使用它来决定它是新的还是现有的。 然而,Northwind在OrderDetails的OrderID和ProductID之间使用复合键。 这些都必须由客户端设置,所以我找不到一种方法来检测新的。 此外,分离图中不存在已删除的OrderDetail,我需要弄清楚已删除的内容并明确删除它。 任何建议将不胜感激。 public override Order Update(Order entity) { dbset.Attach(entity); DataContext.Entry(entity).State = EntityState.Modified; foreach (var orderDetail in entity.OrderDetails) { DataContext.Entry(orderDetail).State = EntityState.Modified; } return entity; }