send the SOAP Request Dynamically To Website knoe
/******Calling Saop Uing WebRequest Nad Response**/
private void CallUsingSOAP(string InXml, out XmlDocument xmlResponse)
{
string strSoapRequest = "";
xmlResponse = null;
string strABCWebServiceUrl = <Mywebservice URL>
strSoapRequest = "";
strSoapRequest += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
strSoapRequest += "<soap:Envelope ";
strSoapRequest += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
strSoapRequest += "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ";
strSoapRequest += "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" ";
strSoapRequest += "xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\" ";
strSoapRequest += ">";
strSoapRequest += "<soap:Header>";
strSoapRequest += "<ContractId/> ";
strSoapRequest += "<AppInfo/> ";
strSoapRequest += "</soap:Header>";
strSoapRequest += "<soap:Body>";
strSoapRequest += InXml;
strSoapRequest += "</soap:Body>";
strSoapRequest += "</soap:Envelope>";
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strSoapRequest);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(strABCWebServiceUrl);
webRequest.Headers.Add("SOAPAction", " ABCMethod");
webRequest.ContentType = "text/xml; charset=utf-8";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
Stream webStream = webRequest.GetRequestStream();
xmlDoc.Save(webStream);
webStream.Close();
WebResponse webResponse = webRequest.GetResponse();
webStream = webResponse.GetResponseStream();
XmlTextReader xmlReader = new XmlTextReader(webStream);
xmlResponse.Load(xmlReader);
webStream.Close();
}
catch (Exception e )
{
throw new Exception ("" + e.Message);
}
/******Calling Saop Uing WebRequest Nad Response**/
private void CallUsingSOAP(string InXml, out XmlDocument xmlResponse)
{
string strSoapRequest = "";
xmlResponse = null;
string strABCWebServiceUrl = <Mywebservice URL>
strSoapRequest = "";
strSoapRequest += "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
strSoapRequest += "<soap:Envelope ";
strSoapRequest += "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" ";
strSoapRequest += "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" ";
strSoapRequest += "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" ";
strSoapRequest += "xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\" ";
strSoapRequest += ">";
strSoapRequest += "<soap:Header>";
strSoapRequest += "<ContractId/> ";
strSoapRequest += "<AppInfo/> ";
strSoapRequest += "</soap:Header>";
strSoapRequest += "<soap:Body>";
strSoapRequest += InXml;
strSoapRequest += "</soap:Body>";
strSoapRequest += "</soap:Envelope>";
try
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(strSoapRequest);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(strABCWebServiceUrl);
webRequest.Headers.Add("SOAPAction", " ABCMethod");
webRequest.ContentType = "text/xml; charset=utf-8";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
Stream webStream = webRequest.GetRequestStream();
xmlDoc.Save(webStream);
webStream.Close();
WebResponse webResponse = webRequest.GetResponse();
webStream = webResponse.GetResponseStream();
XmlTextReader xmlReader = new XmlTextReader(webStream);
xmlResponse.Load(xmlReader);
webStream.Close();
}
catch (Exception e )
{
throw new Exception ("" + e.Message);
}
浙公网安备 33010602011771号