如何将特定的json发送到此服务堆栈请求

时间:2017-04-11 22:54:32

标签: c# servicestack

如何实现方法调用以在ServiceStack中生成此请求?

[Route("/publishmanifest", "POST")]
public class PublishManifest: List<string>, IReturn<bool> {}
To accept requests like:

POST /getconsignments
[
    "ABC1234",
    "ABC5678",
    "ABC9122"
]

我尝试过类似的事情:

    var client = new Client(new JsonServiceClient("www.website.com"));
    var result = client.PublishManifest(myconnotes.ConsignmentNumbers.ToArray());


    public class Client
    {
        private readonly ServiceClientBase _serviceClientBase;

        public Client(ServiceClientBase serviceClientBase)
        {           
            _serviceClientBase = serviceClientBase;
        }
        public bool PublishManifest(PublishManifest request)
        {
            var result = _serviceClientBase.Post(request.ConsignmentNumbers.ToArray());
            return result;
        }
    }

但这不起作用,该怎么做?

由于

1 个答案:

答案 0 :(得分:2)

要调用ServiceStack服务,您只需发送其填充的Request DTO,例如:

var client = new JsonServiceClient("http://www.website.com");
var request = new PublishManifest();
request.AddRange(myconnotes.ConsignmentNumbers.ToArray());
var response = client.Post(request);