Workflow - Component - Developer Guide - Web Service

Published on Wednesday, 9 November 2016

In this Article I'm going to explain how to connect to a Web Service in your component.

We did this in the following Asset Ownership Component.

We will add a reference to an smp.png SMP Web Service.

Build a basic component like we have in previous Articles.

How to: Add, Update, or Remove a Service Reference
https://msdn.microsoft.com/en-us/library/bb628652.aspx

Adding a Service Reference

To add a reference to an external service

  1. In Solution Explorer, right-click the name of the project that you want to add the service to, and then click Add Service Reference.
    The Add Service Reference dialog box appears.

  2. In the Address box, enter the URL for the service, and then click Go to search for the service. If the service implements username/password security, you may be prompted for a username and password.

Note
You should only reference services from a trusted source. Adding references from an untrusted source may compromise security.

Note
You can also select the URL from a drop-down list that stores the last 15 URLs where valid service metadata was found.

A progress bar is displayed while the search is being performed. You can stop the search at any time by clicking Stop.

  1. In the Service list, expand the node for the service that you want to use and select a service contract.

  2. In the Namespace box, enter the namespace that you want to use for the reference.

  3. Click OK to add the reference to the project.
    A service client (proxy) is generated, and metadata describing the service is added to the app.config file.

For the Address we will use the Resource Model

http://localhost/altiris/nswebservice/resourcemodel.asmx

Replace localhost with the name of your SMP Server.

You will have a Using statement in your class that references this new Service.

using Protirus.AssetOwner.Service.ResourceModelService;

In our Run method we can now connect to our Service and perform actions, in this case SaveDataClass

http://localhost/altiris/nswebservice/resourcemodel.asmx?op=SaveDataClass

Declare a client to work with.

public override void Run(IData data)
{
    using (var client = new ResourceModelService.ResourceModelService())
    {
        client.Timeout = Timeout.GetValue<int>(data);
        client.Url = Url.GetValue<string>(data);
        client.Credentials = CredentialCache.DefaultCredentials;
        
        //Do Stuff
        
        client.SaveDataClass(asset, new[] { dcd });
    }
}

Here I've set up inputs to the Component to pass properties I don't want to hardwire like Timeout and URL.

I could have done the same for Credentials but in this case I'm just going to use the DefaultCredentials that are taken from the ApplicationPool.

You could look in the help file for other methods and services you could interact with

E:\Program Files\Altiris\Altiris ASDK\Help\ASDK7.6.chm

Protirus