views:

366

answers:

3

i want to send xml file with userid and pass over HTTPs and then send all other xml file on HTTP using POST method and get the response as a xml file back. in ASP.NET (with vb.net preferred)

The url to which i want to send my xml file is:http://www.hostelspoint.com/xml/xml.php exect xml file pettern is:

<?xml version="1.0" encoding="UTF-8"?>
<OTA_PingRQ xmlns="http://www.opentravel.org/OTA/2003/05"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://www.opentravel.org/OTA/2003/05OTA_PingRQ.xsd"
      TimeStamp="2003-03-17T11:09:47-05:00"
      Target="Production" Version="1.001" PrimaryLangID="en"
      EchoToken="testtoken12">
  <EchoData>Hello</EchoData>
</OTA_PingRQ>
+2  A: 

You should check out the WCF REST Starter Kit, and watch the screencast on HTTP Plain XML (POX) Services which explains step by step how to do just that - create a WCF REST service that will accept and process a plain XML stream.

All the WCF and WCF REST screencasts by Pluralsight are highly recommended! It's excellent material on how to get started and work with WCF.

In addition to that, the MSDN WCF Developer Center is your first point of contact for any questions or more information on WCF and WCF REST.

marc_s
i am using 2.0 framwork so please tell me in that manner.. like: using -System.Net.HttpWebResponse
Rajesh Rolen- DotNet Developer
any chance you could upgrade to .NET 3.5 SP1 ?? It does offer a lot new and improved features and it totally worth the upgrade, and it's really not a "new" .NET, but just additional assemblies
marc_s
A: 

i don't know why u removed correct answer from here but yesterday i got correct answer here. and it is:- (can any one tell me how to do same with HTTPS protocol?)

    string targetUri = "http://www.hostelspoint.com/xml/xml.php";
    System.Xml.XmlDocument reqDoc = new System.Xml.XmlDocument();
    reqDoc.Load(Server.MapPath("~\\myfile.xml"));
    string formParameterName = "OTA_request";
    string xmlData = reqDoc.InnerXml;
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(targetUri);
    string sendString = formParameterName + "=" + HttpUtility.UrlEncode(xmlData);
    byte[] byteStream;
    byteStream = System.Text.Encoding.UTF8.GetBytes(sendString);
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = byteStream.LongLength;
    using (Stream writer = request.GetRequestStream())
    {
        writer.Write(byteStream, 0, (int)request.ContentLength);
        writer.Flush();
    }
    HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
    string respStr = "";
    if (request.HaveResponse)
    {
        if (resp.StatusCode == HttpStatusCode.OK || resp.StatusCode == HttpStatusCode.Accepted)
        {
            StreamReader respReader = new StreamReader(resp.GetResponseStream());
            respStr = respReader.ReadToEnd(); // get the xml result in the string object  
            XmlDocument doc = new XmlDocument();
            doc.LoadXml(respStr);
            Label1.Text = doc.InnerXml.ToString();               
                 }
    } 
Rajesh Rolen- DotNet Developer
+1  A: 

Yes, you can do same thing using HTTPS protocol. You have to add this code before request:

System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate(object sender, X509Certificate certificate, X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
         {
             bool validationResult = true;

             //
             // policy code here ...
             //

             return validationResult;
         };