SharePoint List WebService to Insert Item

Using the SharePoint List WebService to insert an item into a list...

WebService Reference: http://<servername>/_vti_bin/Lists.asmx

try
{
 ws_list.Lists list = new ws_list.Lists();
 list.Credentials = new System.Net.NetworkCredential("username", "password", "domain");
 XmlDocument doc = new XmlDocument();
 XmlElement batch_element = doc.CreateElement("Batch");
 string item = "<Method ID=\"1\" Cmd=\"New\">" + "<Field Name=\"ID\">New</Field>" + "<Field Name=\"Title\">This is a test</Field>" + "</Method>";
 batch_element.InnerXml = item;
 list.UpdateListItems("ListTest", batch_element);
}
catch(Exception ex)
{
string err = ex.Message;
}
 

Another Example

            try
            {

                /*Declare and initialize a variable for the Lists Web service.*/
                siteWebServiceLists.Lists listService = new siteWebServiceLists.Lists();

                /*Authenticate the current user by passing their default credentials to the Web service from the system credential cache.*/
                listService.Credentials = System.Net.CredentialCache.DefaultCredentials;
                listService.Url = url + "/_vti_bin/Lists.asmx";
                System.Xml.XmlNode ndListView = listService.GetListAndView(list, "");
               
                /*Create an XmlDocument object and construct a Batch element and its attributes. Note that an empty ViewName parameter causes the method to use the default view. */
                System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
                System.Xml.XmlElement batchElement = doc.CreateElement("Batch");
               
                batchElement.SetAttribute("OnError", "Continue");
                batchElement.SetAttribute("ListVersion", "1");
                batchElement.InnerXml = "<Method ID='1' Cmd='New'>" +
                "<Field Name='Title'>Title</Field>" +
                "<Field Name='First_x0020_Name'>Wayne</Field>" +
                "<Field Name='Last_x0020_Name'>Magnum</Field>" +
                "</Method>";

                /*Update list items. This example uses the list GUID, which is recommended, but the list display name will also work.*/
                System.Xml.XmlNode n = listService.UpdateListItems(list, batchElement);
                XmlTextReader xr = new XmlTextReader(n.OuterXml, XmlNodeType.Element, null);
                while (xr.Read())
                {
                    if (xr.ReadToFollowing("z:row"))
                    {
                        if (xr["ows_ID"] != null)
                        {
                            Console.WriteLine(xr["ows_ID"].ToString());
                        }
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }