Integration Web Services

In addition to the Data Integration module and the Integration framework, which allow you to move data around in bulk, we also provide you with a webservice which allows you to add and update products and users indiviually.

The productSync webservice is available at the url:

http://your.website/Admin/public/webservices/productManagement/ProductSync.asmx

After adding a reference to this webservice to your project, you can insert or update products with the following code:

string token = textBoxToken.Text; ProductInfo info = new ProductInfo(); info.Id = textBoxProdID.Text; info.Languageid = textBoxLanguageID.Text; info.VariantId = textBoxVariantID.Text; info.Name = textBoxDesc.Text; info.ShortDescription = textBoxShortDesc.Text; //customFields info.customFieldValues = new KeyValuePairOfStringString[2]; info.customFieldValues[1] = new KeyValuePairOfStringString(); info.customFieldValues[1].Key = textBoxCustomFieldKey2.Text; info.customFieldValues[1].Value = textBoxCustomFieldValue2.Text; info.customFieldValues[0] = new KeyValuePairOfStringString(); info.customFieldValues[0].Key = textBoxCustomFieldKey1.Text; info.customFieldValues[0].Value = textBoxCustomFieldValue1.Text; //Groups info.Groups = new ProductSyncService.ArrayOfString() { }; info.Groups.Add(textBoxGroupId1.Text); info.Groups.Add(textBoxGroupId2.Text); var request = new SynchronizeProductRequest(); var webservice = new ProductSyncService.ProductSyncSoapClient("ProductSyncSoap", textBoxURL.Text); try { webservice.SynchronizeProduct(info, token); } catch { //Error handling }

Where the TextboxURL points to the address mentioned above, and the TextBoxToken contains the Installation checksum (found in Settings > System > System Information).

If the info.ID is not set, a new product will be added to the database, with an auto-generated ID. If the ID, VariantID and LanguageID already exist in the Dynamicweb solution, it will be updated. If the VariantID or LangaugeID are left out, the default product/main product will be updated.

After the product is added/updated, the index is updated.

The UserSync webservice is available at:

http://your.website/Admin/public/webservices/userManagement/UserSync.asmx

The implementation is similar to the one described above for Products, with some small differences:

  • If using Visual Studio, add web reference as Service Reference, rather than Web Reference. Otherwise all methods and functions of the reference may not be available.
  • The user must have an ExternalID – this is used when retrieving the user from the Dynamicweb database.
  • By setting the SyncAction on the userInfo object to Delete, it is possible to remove a user from dynamicweb using the service.

Example:

namespace DWUserSync { class Program { private static string token = "b0c4b3d42b57f347069fb6c755e5e6b5"; // Installation checksum private static string address = "http://88.local.dynamicweb.dk/Admin/public/webservices/usermanagement/usersync.asmx"; static void Main(string[] args) { UserReference.UserInfo user = new UserReference.UserInfo(); UserReference.ArrayOfString groups = new UserReference.ArrayOfString(); groups.Add("/DK"); groups.Add("/DK/East"); groups.Add("/NO"); //user.Action = UserReference.SyncAction.DELETE; user.Action = UserReference.SyncAction.UPDATE; user.ExternalId = "007"; user.UserName = "James"; user.Password = "Bond"; user.Name = "James Bond"; user.Groups = groups; var webservice = new UserReference.UserSyncSoapClient("UserSyncSoap", address); webservice.SynchronizeUser(user, token); } } }