Important note about Windows Communication Foundation (WCF) service references:If you're using the newer Windows Communication Foundation (WCF) soap service reference (instead of legacy "Web Reference") you might want to find & replace "\[System.Xml.Serialization.*(*Order=*)\]" with nothing in your Visual Studio Reference.cs file so that changes to the API don't silently break your reference definition. The [Order()] attributes are not required and they make service references far less robust.
WORKetc.VeetroWebServiceMethods service = new WORKetc.VeetroWebServiceMethods();// Ensure the service URL is correct, use your account!service.Url = "http://youraccountdomain/Xml";WORKetc.AuthenticateResult res = service.AuthenticateWebSafe("user@domain.com", "password");if (res.Code == WORKetc.AuthenticateCode.Success){ // We have a valid session, add to cookies or http header service.CookieContainer = new System.Net.CookieContainer(); service.CookieContainer.Add(new System.Net.Cookie("VeetroSession", res.SessionKey, "/", new Uri(service.Url).Host)); // Call some Employee-only method WORKetc.Entity[] ar = service.GetAllEntities(); System.Diagnostics.Debug.WriteLine(ar.Length);}else{ // login failed System.Diagnostics.Debug.WriteLine("Login failed with " + res.Message);}
void AddPerson(){ // Instantiate the webservice WORKetc.VeetroWebServiceMethods service = new WORKetc.VeetroWebServiceMethods(); // Ensure the service URL is correct, use your account! service.Url = "http://youraccountdomain/Xml"; WORKetc.AuthenticateResult res = service.AuthenticateWebSafe("user@domain.com", "password"); if (res.Code != WORKetc.AuthenticateCode.Success) { // Login has failed here.. MessageBox.Show("Login failed with " + res.Message); return; } // We have a valid session, add to cookies or http header service.CookieContainer = new System.Net.CookieContainer(); service.CookieContainer.Add(new System.Net.Cookie("VeetroSession", res.SessionKey, "/", new Uri(service.Url).Host)); /// // Create a new person object // Person p = new Person(); p.EntityID = 0; // EntityID zero will tell the service, this is a new contact. p.FirstName = "John"; p.Surname = "Doe"; p.Email = "john@doe.com"; // Create an address Veetro.Address a = new Veetro.Address(); a.Country = "Canada"; a.Phone = "902 555 0000"; a.PostalCode = "B0J 3C0"; a.StateOrProv = "NS"; a.Street = "Some Street"; a.Suburb = "Sherbrooke"; p.Addresses = new Veetro.Address[] { a }; // Save the person. SetPerson will return the object again // except it will be populated with it's new unique EntityID. try { p = service.SetPerson(p); MessageBox.Show("New Person created with ID " + p.EntityID + "."); } catch (Exception x) { MessageBox.Show("Create person failed with " + x.Message); }}