Public stringSoaprequest (stringUrlstringMessagestringtype, Encoding Encoding) { stringresult =string. Empty; Stream Reqstr=NULL; System.IO.Stream Responsestream=NULL; System.IO.StreamReader Reader=NULL; Try{HttpWebRequest Request= WebRequest.Create (URL) asHttpWebRequest; 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,0, Buff. Length); Reqstr. Flush (); Reqstr. Close (); Reqstr. Dispose (); Reqstr=NULL; } //receive the returned pageHttpWebResponse response = Request. GetResponse () asHttpWebResponse; Responsestream=Response. GetResponseStream (); Reader=NewSystem.IO.StreamReader (responsestream, encoding); Result=Reader. ReadToEnd (); if(Onstatecomplate! =NULL) onstatecomplate (result, FSPC); if(Onreplycomplate! =NULL) onreplycomplate (result, FSPC); returnresult; } Catch(Exception ex) {Throwex; } 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 stringGetStringSOAP1 (Hashtable HT,stringtarget) {StringBuilder Body=NewStringBuilder (); 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 ()); intindex =2; 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>"); returnbody. ToString (); }
HTTP SOAP Request