Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Xml communication

Status
Not open for further replies.

Eli20

Programmer
Oct 30, 2003
119
MX
Hi, im trying to biuld an applications that consist on two parts:
One is a windows application that has its own database
The second is a web page where all the information from all the windows applications gets together.

Im new to .net, and what i want to make is that my windows applications send an xml file with all the data to the webpage (asp.net) and it insterts it to the main database, and then the other way around, but im a bit lost.

can anyone explain me a bit how to make the windows application connect to the webpage, and how it sends the xml file? and how the page recives it so it can process the information??

thank You very very much

Eli
 
try something like this:
Code:
    /// <summary>
    /// submits an xml set as an array of bytes, to a servlet paraser
    /// </summary>
    /// <param name="uri">full URL of the parser</param>
    /// <param name="xml">string containing a Xml document</param>
    /// <param name="usr">User Name</param>
    /// <param name="psd">Password</param>
    /// <param name="dmn">Domain(I am using String.Empty)</param>
    /// <returns>response from the servlet as a string </returns>
    private String Submit_XML(String uri,String xml,String usr,String psd,String dmn)
    {
      try
      {
        //create a client
        System.Net.WebClient cli = new WebClient();

        //setup the credentials
        CredentialCache myCache = new CredentialCache(); 
        myCache.Add(new Uri(uri), "Basic", new NetworkCredential(usr,psd,dmn));
        cli.Credentials = myCache;

        //add content header
        cli.Headers.Add("Content-Type","application/x-[URL unfurl="true"]www-form-urlencoded");[/URL]

        // Decode and return the response from uploading the input string using the HTTP 1.0 POST method.
        return Encoding.ASCII.GetString(cli.UploadData(uri,"POST",Encoding.ASCII.GetBytes(xml)));
      }
      catch (Exception e) 
      {
        return e.ToString();
      }
    }

    ///<summary>
    ///button clicked to kick off the xml upload
    ///</summary>
    private void button1_Click(object sender, System.EventArgs e)
    {
      String uri = textBox1.Text;
      String xml = richTextBox1.Text;
      String dmn = String.Empty;
      String rsp = String.Empty;
      richTextBox2.Clear();
      richTextBox2.Text = "SUBMITTING";
      richTextBox2.Refresh();

      if((txtUser.Text != String.Empty) && (txtPassword.Text != String.Empty))
      {
        rsp = Submit_RDL(uri,xml,txtUser.Text,txtPassword.Text,dmn);

        richTextBox2.Text = rsp;
      }
      else
      {
        richTextBox2.Text = "Need User Name and Password";
      }
    }

I use similar code to post to a java servlet, but posting to an asp page should not be to different.

Depending on how your page is setup you may want to use the WebClient.UploadValues() or WebClient.OpenWrite() functions.

Let us know how it goes.

Randall2nd
 
ill try it, thank you very much..

ill let you know how it works

Eli
 
hi, i just tried your code, but i cannt make it work, i get an error from the server.

it says internal Server Error 500.

i dont know if im doing it right, my code looks more or less like this, im just testing it:

this is my service method:
Code:
[WebMethod]
public string ReadXML(string strXml){
    return strXml;
}

and this how im trying to call it, from a different windows app:
Code:
private void button1_Click(object sender, System.EventArgs e) {
   System.Net.WebClient cli= new System.Net.WebClient();
   cli.Headers.Add("Content-Type","application/x-[URL unfurl="true"]www-form-urlencoded");[/URL]
   string uri="[URL unfurl="true"]http://localhost/XmlTest/test.asmx";[/URL]
   string xml="anystring";
   CredentialCache myCache = new CredentialCache(); 
   myCache.Add(new Uri(uri), "Basic", new NetworkCredential("","",""));
   cli.Credentials = myCache;

		
   try{
      TextBox1.Text=Encoding.ASCII.GetString(cli.UploadData(uri,"POST",Encoding.ASCII.GetBytes(xml)));
   }catch(Exception ex){
	MessageBox.Show(ex.ToString());
   }

what am i doing wrong?? please help..

thank You very much
Eli
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top