简体   繁体   English

如何测试将输入作为来自REST客户端工具的流的WCF服务方法

[英]How to test wcf service method that takes input as stream from REST client tool

I am creating wcf service that accepts stream as a input parameter. 我正在创建将流作为输入参数的wcf服务。

Here is my method in Contract 这是我在合同中的方法

 [OperationContract(Name = "PostSampleMethod")]
        [WebInvoke(Method = "POST",
         UriTemplate = "PostSampleMethod")]

        string PostSampleMethod(Stream data);

And here is the implementation of it 这是它的实现

 public string PostSampleMethod(Stream data)
        {
            // convert Stream Data to StreamReader
            StreamReader reader = new StreamReader(data);
            // Read StreamReader data as string
            string xmlString = reader.ReadToEnd();
            string returnValue = xmlString;
            // return the XMLString data
            return returnValue;
        }

I am using ARC or Boomerang tool to test my service's method. 我正在使用ARC或Boomerang工具来测试我的服务方法。 My problem is what input data or in what format I need to send from REST client tool to test this method. 我的问题是我需要从REST客户端工具发送什么输入数据或哪种格式的数据来测试此方法。

Any help is much appreciated. 任何帮助深表感谢。

Since you read the incoming stream as string( by using StreamReader ), you can send any string(xml, json, free format) to your server. 由于您将传入的流读取为字符串( 使用StreamReader ),因此可以将任何字符串(xml,json,自由格式)发送到服务器。

var client = new HttpClient();
var content = new StringContent("aaaa");
var resp = await client.PostAsync("http://....../PostSampleMethod", content);
var status = resp.StatusCode;
var retValue = await resp.Content.ReadAsStringAsync();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM