zoukankan      html  css  js  c++  java
  • SoapUI 设置 request data with json body

    --背景

    使用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),如图

  • 相关阅读:
    MVVM知识库总结
    C#常用类汇总
    silverlight调用MVC WebApi方法
    IE调试方法(一)<转>
    PHP中关于超链接的拼接问题
    intval()和(int)转换使用与区别
    ThinkPHP模板(一)
    修改ThinkSNS网站入口
    js中的this和apply
    Thinkphp的Volist标签
  • 原文地址:https://www.cnblogs.com/atuotuo/p/5457451.html
Copyright © 2011-2022 走看看