Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
1)my application is windows application (RFID application)

Present we are sending data to oracle,they are asked to change from oracle to SAP

2) For that purpose they are given SOAP web service we need to send parameters through url i googled and i found some code but it is not triggering to that url.

3) I tried with SOAP UI data send's successfully but using application data is not triggered.

Please give solution for this......

What I have tried:

private void button2_Click(object sender, EventArgs e)
{
//String url = "https://selfsolve.apple.com/wcResults.do";
//URL obj = new URL(url);
//URLConnection con = url.openConnection();
//HttpsURLConnection con = (HttpsURLConnection)obj.openConnection();

//URL url = new URL("http://iltdpodev.itc.in:50000/dir/wsdl?p=ic/de7a99a9145f31eb931f8792ad1b7d51");
//HttpURLConnection urlConnection = (HttpURLConnection)url.openConnection();

var url = "http://iltdpodev.itc.in:50000/dir/wsdl?p=ic/de7a99a9145f31eb931f8792ad1b7d51";
var action = "http://sap.com/xi/WebService/soap1.1";


var soapEnvelopeXml = CreateSoapEnvelope();
var soapRequest = CreateSoapRequest(url, action);
InsertSoapEnvelopeIntoSoapRequest(soapEnvelopeXml, soapRequest);

using (var stringWriter = new StringWriter())
{
using (var xmlWriter = XmlWriter.Create(stringWriter))
{
soapEnvelopeXml.WriteTo(xmlWriter);
xmlWriter.Flush();
}
}

// begin async call to web request.
var asyncResult = soapRequest.BeginGetResponse(null, null);

// suspend this thread until call is complete. You might want to
// do something usefull here like update your UI.
var success = asyncResult.AsyncWaitHandle.WaitOne(TimeSpan.FromSeconds(50));

//if (!success) return null;

// get the response from the completed web request.
//using (var webResponse = soapRequest.EndGetResponse(asyncResult))
//{
// string soapResult;
// var responseStream = webResponse.GetResponseStream();
// if (responseStream == null)
// {
// return null;
// }
// using (var reader = new StreamReader(responseStream))
// {
// soapResult = reader.ReadToEnd();
// }
// return soapResult;
//}
}

private static HttpWebRequest CreateSoapRequest(string url, string action)
{
var webRequest = (HttpWebRequest)WebRequest.Create(url);

webRequest.Headers.Add("SOAPAction", action);
webRequest.ContentType = "text/xml;charset=\"utf-8\"";
webRequest.Accept = "text/xml";
webRequest.Method = "POST";
NetworkCredential credential = new NetworkCredential("", "");
webRequest.Credentials = credential;
webRequest.KeepAlive = true;
webRequest.UseDefaultCredentials = true;
return webRequest;
}

private static XmlDocument CreateSoapEnvelope()
{
string s1 = " <soapenv:envelope xmlns:soapenv="\" http:="" schemas.xmlsoap.org="" soap="" envelope="" \""="" xmlns:fus="\" fusion_pp_rfid_i_pp3_001_rfidmarryingwithubc\""=""> "
+ " <soapenv:header> "
+ " <soapenv:body> "
+ " <fus:mt_rfid_data_sender> "
+ " <rfid_data> "
+ " <rfid_tag_no>501 "
+ " <feeding_line_number>502 "
+ " <step_number>503 "
+ " <ubc_number>504 "
+ " <status>505 "
+ " "
+ " "
+ " "
+ " ";

string s2 = " <soapenv:envelope xmlns:soapenv="\" http:="" schemas.xmlsoap.org="" soap="" envelope="" \""="" xmlns:fus="\" fusion_pp_rfid_i_pp3_001_rfidmarryingwithubc\""=""> "
+ " <soapenv:header> "
+ " <soapenv:body> "
+ " <fus:mt_rfid_data_sender> "
+ " <rfid_data> "
+ " <rfid_tag_no>501 "
+ " <feeding_line_number>502 "
+ " <step_number>503 "
+ " <ubc_number>504 "
+ " <status>505 "
+ " "
+ " "
+ " "
+ " ";

var soapEnvelope = new XmlDocument();
soapEnvelope.LoadXml(s1); //the SOAP envelope to send
return soapEnvelope;
}

private static void InsertSoapEnvelopeIntoSoapRequest(XmlDocument soapEnvelopeXml, HttpWebRequest webRequest)
{
using (Stream stream = webRequest.GetRequestStream())
{
soapEnvelopeXml.Save(stream);

}
}
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900