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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sending XML to Webservice 1

Status
Not open for further replies.

fergmj

Programmer
Feb 21, 2001
276
US
I am using XMLTextWriter to create XML. Can someone tell me how to send this to a webservice being hosted by someone else?

Lets say my Webservice was with an exposed method of importLead

THANKS!

Code:
XmlTextWriter writer = new XmlTextWriter(/*Response.OutputStream*/ Server.MapPath("myleads.xml"), Encoding.UTF8);
        writer.WriteStartDocument();
        writer.WriteStartElement("Lead_list");

        while (mdr.Read())
        {
            //mdr.GetString(0); UniqueID
            //mdr.GetString(1); Vendor
            //mdr.GetString(2); FirstName
            //mdr.GetString(3); LastName
            //mdr.GetString(4); Address1
            //mdr.GetString(5); Address2
            //mdr.GetString(6); City
            //mdr.GetString(7); State
            //mdr.GetString(8); ZipCode
            //mdr.GetString(9); PrimaryPhone
            //mdr.GetString(10); SecondaryPhone
            //mdr.GetString(11); Email
            //mdr.GetString(11); Notes

            writer.WriteStartElement("Lead");

            writer.WriteElementString("Vendor", mdr.GetString(1));
            writer.WriteElementString("UniqueID", mdr.GetString(0));
            writer.WriteElementString("FirstName", mdr.GetString(2));
            writer.WriteElementString("LastName", mdr.GetString(3));
            writer.WriteElementString("Address1", mdr.GetString(4));
            writer.WriteElementString("Address2", mdr.GetString(5));
            writer.WriteElementString("City", mdr.GetString(6));
            writer.WriteElementString("State", mdr.GetString(7));
            writer.WriteElementString("ZipCode", mdr.GetString(8));
            writer.WriteElementString("PrimaryPhone", mdr.GetString(9));
            writer.WriteElementString("SecondaryPhone", mdr.GetString(10));
            writer.WriteElementString("Email", mdr.GetString(11));
            writer.WriteElementString("Notes", mdr.GetString(12));

            writer.WriteEndElement();    
        }

        writer.WriteEndElement();
        writer.WriteEndDocument();
        writer.Close();
 
start by creating a webrequest. set the appropriate properties. this will depend on ssl, authentication, the method (get/post)
then write the xml to the request and send

here is an example from another page. this uses the post method to send information to a webpage and get the reponse back.
Code:
string strNewValue;
string strResponse;

// Create the request obj
HttpWebRequest req = (HttpWebRequest) WebRequest.Create("[URL unfurl="true"]http://someur.com/somepage.aspx");[/URL]

// Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-[URL unfurl="true"]www-form-urlencoded";[/URL]
strNewValue = strFormValues + "&param1=value1&parm2=value2";
req.ContentLength = strNewValue.Length;

// Write the request
StreamWriter stOut = new StreamWriter (req.GetRequestStream(), System.Text.Encoding.ASCII);
stOut.Write(strNewValue);
stOut.Close();

// Do the request to get the response
StreamReader stIn = new StreamReader(req.GetResponse().GetResponseStream());
strResponse = stIn.ReadToEnd();
stIn.Close();

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top