您的位置:首页 > 产品设计 > UI/UE

SoapUI 设置 request data with json body

2016-05-04 10:11 162 查看
--背景

使用WCF定义REST风格的WebService,如下:

[ServiceContract]
public interface INISTService
{
[OperationContract, WebInvoke(UriTemplate = "/EnrollTP/{context}",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
Method = "POST",
BodyStyle = WebMessageBodyStyle.Bare)]
bool Enroll(string packageStr, string context);

}

--编写测试代码

由于参数“packageStr”的内容过大超过URI的限定长度,需要将其放入Request对象中,在自己编写客户端代码测试时,将packageStr的值转为BASE64STRING放入参数sendData中,并将其存入到HTTPWebRequest对象中。

HttpWebRequest webRequest = HttpWebRequest.Create(uri) as HttpWebRequest;
webRequest.Method = "POST";
webRequest.Accept = AcceptHeader;
webRequest.ContentType = ContentType;
if (timeOut != 0)
webRequest.Timeout = timeOut;
Stream stream = webRequest.GetRequestStream();
using (StreamWriter writer = new StreamWriter(stream))
{
writer.Write(sendData);
}

--使用SoapUI时,按照接口定义设置request data为JSON类型(copy BASE64STRING into),如图

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: