2014-07-07 3 views
0

RestSharp 클라이언트를 통해 RESTful WCF 서비스 기능을 제대로 사용할 수 있지만 제대로 작동하지 않습니다.RestSharp JSON 비 윤활 처리

static void Main(string[] args) 
{ 
    Console.ReadLine(); 

    var client = new RestClient("http://localhost:5463/RESTDragon.svc"); 
    client.AddDefaultHeader("ContentType", "application/json"); 
    var request = new RestRequest("/getconfig/11123") {Method = Method.GET, RequestFormat = DataFormat.Json}; 
    var response = client.Execute<DragonConfig>(request); 
    Console.WriteLine("Response: " + response.Content); 
    Console.ReadLine(); 
} 

것은이 반환 그러나 :

Response: {"getconfigResult":{"Data":"DAtaaaaaa","Name":"Test"}} 

내가 response.Data를 통해 드 - 직렬화 된 데이터에 액세스 할 수 없습니다 나는 여기

[ServiceContract] 
public interface IRestDragon 
{ 
    [OperationContract(Name = "getconfig")] 
    [WebInvoke(Method = "GET", UriTemplate = "getconfig/{id}", BodyStyle = WebMessageBodyStyle.Wrapped, 
     ResponseFormat = WebMessageFormat.Json, RequestFormat = WebMessageFormat.Json)] 
    DragonConfig GetConfig(string id); 
} 

public class RestDragon : IRestDragon 
{ 
    public DragonConfig GetConfig(string id) 
    { 
     var config = new DragonConfig {Name = "Test", Data = "DAtaaaaaa"}; 
     return config; 
    } 
} 

그리고 내가 서비스를 사용하는 방법입니다. *. null로 돌아오고 데이터는 Content에 표시되지만 JSON 형식에서는 이상한 getconfigResult 식별자가 표시됩니다.

답변

0

Setting BodyStyle = WebMessageBodyStyle.Bare가 문제를 수정했습니다.

0

response.Content 대신 response.Data에 액세스해야 비 직렬화 된 개체를 가져올 수 있습니다.

+0

문제는 BodyStyle = WebMessageBodyStyle.Wrapped입니다. Bare로 설정하면 문제가 해결되었습니다. – 1232133d2ffa

관련 문제