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),如图
使用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),如图
相关文章推荐
- UIImage两种初始化的区别
- LeMaker Guitar:扩展系统分区
- 400 (bad request) post
- UIView中坐标的转换
- 【Leetcode】Top K Frequent Elements
- ios 使用UINavagationController时,push,pop方法执行的一些方法 - shidaying
- hibernate query.list() 返回的数据类型
- IntelliJ IDEA 安装插件 (vue)
- UICollectionViewFlowLayout使用示例
- 安装ZeroMQ时候,会出现configure: error: Package requirements (libsodium) were not met,解决办法如下
- UIBezierPath精讲
- iOS UICollectionView基本属性 和 代理方法
- 如何获得select被选中option的value和text
- require()函数
- UIImage的两种初始化方式
- include()和require()是特殊的语言结构,在条件语句中使用必须将其放在语句组中
- UI高总结
- activiti uuid主键
- activiti uuid主键
- Extension Methods (C# Programming Guide)