HTTP SOAP Request
public string SoapRequest(string url, string message, string type, Encoding encoding)
{
string result = string.Empty;
Stream reqstr = null;
System.IO.Stream responseStream = null;
System.IO.StreamReader reader = null;
try
{
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = type.ToString();
request.ContentType = "application/soap+xml;charset=UTF-8;action=\"" + url + "\"";
request.Headers.Add("SOAPAction", url); if (type.ToString().ToLower() == "post")
{
reqstr = request.GetRequestStream();
byte[] buff = encoding.GetBytes(message);
reqstr.Write(buff, , buff.Length);
reqstr.Flush();
reqstr.Close();
reqstr.Dispose();
reqstr = null;
}
// 接收返回的页面
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
responseStream = response.GetResponseStream();
reader = new System.IO.StreamReader(responseStream, encoding);
result = reader.ReadToEnd();
if (OnStateComplate != null)
OnStateComplate(result, fspc);
if (OnReplyComplate != null)
OnReplyComplate(result, fspc);
return result;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (reader != null)
{
reader.Close();
reader.Dispose();
}
if (reqstr != null)
{
reqstr.Flush();
reqstr.Close();
reqstr.Dispose();
}
if (responseStream != null)
{
responseStream.Flush();
responseStream.Close();
responseStream.Dispose();
}
} }
public static string GetStringSOAP1(Hashtable ht,string target)
{
StringBuilder body = new StringBuilder();
body.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
body.Append("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
body.Append("<soap:Body>");
body.Append("<"+target+" xmlns=\"http://service.pubinfo.com.cn\">");
body.AppendFormat("<in0>{0}</in0>", ht["loginName"].ToString());
body.AppendFormat("<in1>{0}</in1>", ht["loginPWD"].ToString());
int index = ;
if (ht.ContainsKey("mobiles") && !string.IsNullOrEmpty(ht["mobiles"].ToString()))
{
body.AppendFormat("<in{1}>{0}</in{1}>", ht["mobiles"].ToString(),index++);
}
if (ht.ContainsKey("content") && !string.IsNullOrEmpty(ht["content"].ToString()))
{
body.AppendFormat("<in{1}>{0}</in{1}>", ht["content"].ToString(), index++);
}
if (ht.ContainsKey("sendNo") && !string.IsNullOrEmpty(ht["sendNo"].ToString()))
{
body.AppendFormat("<in{1}>{0}</in{1}>", ht["sendNo"].ToString(), index++);
}
body.Append("</"+target+"></soap:Body></soap:Envelope>");
return body.ToString();
}
HTTP SOAP Request的更多相关文章
- soap request by afnetworking2.X/3.X
for 2.X 参考 http://jiapumin.iteye.com/blog/2109378 AFHTTPRequestOperationManager *manager = [AFHTTPRe ...
- 【转载】C# HttpWebRequest 发送SOAP XML
调用webservice的几种方法: 方法一:添加web引用(简单/方便 局限客户端是.net) 方法二:Post xml(本文重点讲述) 方法三:使用微软MSXML2组件(好像在window ser ...
- 译-Web Service剖析: XML, SOAP 和WSDL 用于独立于平台的数据交换
本文是翻译内容,原文参见: Anatomy of a Web Service: XML, SOAP and WSDL for Platform-independent Data Exchange We ...
- SOAP Binding: Difference between Document and RPC Style Web Services
SOAP Binding: Difference between Document and RPC Style Web Services 20FLARES Twitter 1Facebook 9Goo ...
- 通过JavaScript调用SOAP终结点执行实体消息
关注本人微信和易信公众号: 微软动态CRM专家罗勇 ,回复148或者20150813可方便获取本文,同时可以在第一时间得到我发布的最新的博文信息,follow me! 利用OData终结点可以方便的对 ...
- webService(SOAP)性能测试脚本
本文以天气预报的webService为基础进行学习 webService地址:http://www.webxml.com.cn/WebServices/WeatherWebService.asmx ...
- C#,SOAP1.1与1.2的发布与禁用(SOAP 1.2 in .NET Framework 2.0)
来源:https://www.codeproject.com/Articles/11878/SOAP-in-NET-Framework SOAP 1.2 in .NET Framework 2.0 ...
- Loadrunner 9.5_webservice(SOAP)性能测试
WebService定义:Webservice是一种新的使用基于XML标准和协议来交换信息的WEB应用程序.是基于SOAP(简单对象访问协议)消息的应该协议,只是为WEB页面或可执行程序提供编程接口. ...
- (转)Java实现Web Service过程中处理SOAP Header的问题
网上有篇文章,大致这么说的(如下文),最后我采用的wsimport -XadditionalHeaders的方式. StrikeIron offers two authentication meth ...
随机推荐
- 【转】【Egit】如何将eclipse中的项目上传至Git
1.下载egit插件 打开Eclipse,git需要eclipse授权,通过网页是无法下载egit的安装包的.在菜单栏依次打开eclipse→help→install new software→add ...
- <T> List<T>前面<T>的意思
先看例子: import java.util.*; class Fruit { public String toString() { return "Fruit"; } } cla ...
- [SOJ] 无路可逃?
Description 唐僧被妖怪关在迷宫中.孙悟空好不容易找到一张迷宫地图,并通过一个魔法门来到来到迷宫某个位置.假设迷宫是一个n*m的矩阵,它有两种地形,1表示平地,0表示沼泽,孙悟空只能停留在平 ...
- 【卷二】网络二—TCP服务器与客户端
经过上回简单地介绍,大家对服务器多少应该清楚一些了吧!还记得TCP: (Transmission Control Protocol) 传输控制协议? 还记得IP: (Internet Protocol ...
- 使用ajax和history.pushState无刷新改变页面URL(转)
表现 如果你使用chrome或者firefox等浏览器访问本博客.github.com.plus.google.com等网站时,细心的你会发现页面之间的点击是通过ajax异步请求的,同时页面的URL发 ...
- mysql bit类型数据库中无法显示
表an_bit bit类型字段id select bin(id+0) from an_bit显示二进制 select id+0 from an_bit显示十进制 http://blog.csdn.ne ...
- How to fix 'sudo: no tty present and no askpass program'以及硬盘序列号的读写
在调用system命令读写硬盘序列号的过程中遇到问题,报错如下: sudo: no tty present and no askpass program 发现此问题是由于帐号并没有开启免密码导致的 . ...
- Hibernate配置详细解释
hibernate.cfg.xml <!--标准的XML文件的起始行,version='1.0'表明XML的版本,encoding='gb2312'表明XML文件的编码方式--> < ...
- spring+ibatis问题1—— 程序报错:java.sql.SQLException: Io 异常: Connection reset by peer, socket write error; ”或“java.sql.SQLException 关闭的连接”异常
转自:http://blog.sina.com.cn/s/blog_1549fb0710102whz2.html spring+ibatis程序测试时报错:java.sql.SQLException: ...
- HDU 1525 Euclid's Game
题目大意: 题目给出了两个正数a.b 每次操作,大的数减掉小的数的整数倍.一个数变为0 的时候结束. 谁先先把其中一个数减为0的获胜.问谁可以赢.Stan是先手. 题目思路: 无论a,b的值为多少,局 ...