相关疑难解决方法(0)

使用restsharp序列化对象并将其传递给WebApi而不是序列化列表

我有一个看起来像的视图模型.

public class StoreItemViewModel
{
    public Guid ItemId { get; set; }
    public List<Guid> StoreIds { get; set; }
    [Required]
    public string Description { get; set; }
    //[Required]
    //[DataMember(IsRequired = true)]
    public int ItemTypeId { get; set; }


}
Run Code Online (Sandbox Code Playgroud)

我有一个使用RestSharp的小帮手.

public static IRestResponse Create<T>(object objectToUpdate, string apiEndPoint) where T : new()
    {
        var client = new RestClient(CreateBaseUrl(null))
        {
            Authenticator = new HttpBasicAuthenticator("user", "Password1")
        };

        var request = new RestRequest(apiEndPoint, Method.POST);
        //request.JsonSerializer = new JsonSerializer();
       // {RequestFormat = DataFormat.Json};
        request.AddObject(objectToUpdate);
       // …
Run Code Online (Sandbox Code Playgroud)

c# asp.net-mvc json.net restsharp asp.net-web-api

12
推荐指数
3
解决办法
4万
查看次数

使用RestSharp构建XML请求

我正在尝试使用RestSharp和C#使用REST API.我正在使用的API文档提供了一个示例XML请求:

<?xml version='1.0' encoding='UTF-8'?>  
<messages>  
 <accountreference>EX0000000</accountreference> 
 <from>07700900654</from>
 <message>  
  <to>07700900123</to>  
  <type>SMS</type>  
  <body>Hello Mr Sands.</body>
 </message>  
 <message>  
  <to>07700900124</to>  
  <type>SMS</type>  
  <body>Hello Mr Mayo.</body>
 </message>  
</messages>
Run Code Online (Sandbox Code Playgroud)

我正在努力了解如何以他们想要的格式构建请求(多个元素称为"消息")

我已经为RestSharp创建了这些类来序列化:

public class messages
{
    public string accountreference { get; set; }

    public string from { get; set; }

    public message message { get; set; }
}

public class message
{
    public string to { get; set; }

    public string body { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

这是我的RestSharp代码:

var client = new RestClient("http://api.url.com/v1.0")
                         {
                             Authenticator =
                                 new …
Run Code Online (Sandbox Code Playgroud)

c# xml rest restsharp

6
推荐指数
1
解决办法
7954
查看次数

标签 统计

c# ×2

restsharp ×2

asp.net-mvc ×1

asp.net-web-api ×1

json.net ×1

rest ×1

xml ×1