Introduction
Web Services signal a new age of trivial distributed application development. While Web Services are not intended nor do they have the power to solve every distributed application problem, they are an easy way to create and consume services over the Internet. One of the design goals for Web Services is to allow companies and developers to share services with other companies in a simple way over the Internet.
Web services take Web applications to the next level.
Using Web services your application can publish its function or message to the rest of the world.
Web services use XML to code and decode your data and SOAP to transport it using open protocols.
With Web services your accounting departments Win 2k servers billing system can connect with your IT suppliers UNIX server.
Using Web services you can exchange data between different applications and different platforms.
With Microsoft .Net platform it is a simple task to create and consume Web Services. In this article am going to show how to call a published web services inside a web project.
I use a test published web services; Extentrix Web Services 2.0 Application Edition (http://www.extentrix.com/webservices/2.0.0/ExtentrixWebServicesForCPS.asmx) that Extentrix published for the developer community to help them in testing and developing.
So I’ll explain simply the functions of this web services APIs. In general Extentrix Web Services for Citrix Presentation Server helps you get information about a published application for a specific client with the specified details, server types, and client types. It also returns the <place w:st="on"><city w:st="on">ICAfile description to be used to launch an application with a given parameter and checks the user's credentials and returns true if they are valid.
For more information, visit http://www.extentrix.com/Web%20Services/Index.htm
You can find more samples, use this web services, and test it on http://www.extentrix.com/Web%20Services/Test%20Drive.htm?id=6
Background
Knowledge in ASP.NET is preferred
Using the code
Simple Steps to consume web service:
- Create Web Site project
- Add web Reference
- Call the web services APIs inside the code
First Step: Create Web Site project
1. To create new Web Site project, choose New from File menu, then choose Web Site as shown below.
<shapetype id="_x0000_t75" stroked="f" path="m@4@5l@4@11@9@11@9@5xe" o:spt="75" o:preferrelative="t" filled="f" coordsize="21600,21600"><stroke joinstyle="miter"><formulas><f eqn="if lineDrawn pixelLineWidth 0"><f eqn="sum @0 1 0"><f eqn="sum 0 0 @1"><f eqn="prod @2 1 2"><f eqn="prod @3 21600 pixelWidth"><f eqn="prod @3 21600 pixelHeight"><f eqn="sum @0 0 1"><f eqn="prod @6 1 2"><f eqn="prod @7 21600 pixelWidth"><f eqn="sum @8 21600 0"><f eqn="prod @7 21600 pixelHeight"><f eqn="sum @10 21600 0"></formulas><path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"><lock v:ext="edit" aspectratio="t">
2. Choose ASP.NET Web Site. Name the project and click OK
Second Step: Add web Reference
After creating the Web Site project, it’s time to add a web reference for our web service.
1. In the solution explorer, right click the project node, choose Add Web Reference
2. A new window with Add Web Reference title will be opened.
In the URL field, insert the URL for the web service. In this tutorial as I mentioned before I’ll use the test published web services form Extentrix. “Extentrix Web Services 2.0 – Application Edition”
http://www.extentrix.com/webservices/2.0.0/ExtentrixWebServicesForCPS.asmx
After clicking the Go button you will see the web services APIs.
3. Set a name for your web service reference in the web reference name field and click Add Reference
Third Step: Call the web services APIs inside the code
After a successful adding to the web service, now we are ready to call the web services APIs inside our project.
1. First we need to add the added web reference to our class.
“ExtentrixWS” is the name of the added web service from the previous step.
using ExtentrixWS;
2. Create a proxy object for our added web service reference, where the ExtentrixWebServicesForCPS is the name of the Web Services
private ExtentrixWS.ExtentrixWebServicesForCPS proxy;
3. As I explained before we need credentials to pass to Citrix Presentation Server, we will pass these credentials through the web services APIs
private Credentials credentials;
Initialize the proxy and the credentials objects
proxy = new ExtentrixWebServicesForCPS();
credentials = new Credentials();
4. Set the values for Citrix credentials. I set the credentials values for the test of Extentrix Web Service.
credentials.Password = "demo";
credentials.UserName = "citrixdesktop";
credentials.Domain = "testdrive";
credentials.PasswordEncryptionMethod = 0;
credentials.DomainType = 0;
Now we can call any web services available as simple as calling any ordinary function.
5. Call the GetApplicationsByCredentialsEx web service. This web service takes the following parameters:
- Credentials: Citrix Credential to access Citrix Presentation Server Farm.
- Client Name: pass your machine name
- Client IP: pass your machine IP
- Desired Details : what the details you asked for
- Server Types: pass “all”
- Client Types: pass “all”
Am not going to explain Extentrix web services APIs, if you are interested you can go to http://www.extentrix.com/Web%20Services/Index.htm and look for it.
This API returns an array of ApplicationItemEx, this class will be built for you once you add the web reference.
This class contains the published application properties. I used this web service to get all the published applications, and then I created an ImageButton for each application.
ApplicationItemEx[] items = proxy.GetApplicationsByCredentialsEx(credentials, Request.UserHostName,
Request.UserHostAddress, new string[] { "icon","icon-info"}, new string[]{ "all" },
new string[] { "all"});
for (int i = 0; i < items.Length; i++) {
System.Web.UI.WebControls.ImageButton app = new System.Web.UI.WebControls.ImageButton();
app.ImageUrl = createIcon(items[i].InternalName,items[i].Icon);
app.ToolTip = items[i].InternalName;
AppList.Controls.Add(app);
app.Click += new
System.Web.UI.ImageClickEventHandler(this.OnApplicationClicked);
}
Finally another example in calling web service is to launch the published application.
In this example, in the event handler of the applications ImageButtons I launch the clicked application.
I get the <place w:st="on"><city w:st="on">ICA file content by calling LaunchApplication web service.
Then I write the <place w:st="on"><city w:st="on">ICA file content to the response to launch the application.
private
void OnApplicationClicked (object
sender, System.EventArgs e)
{
ServicePointManager.Expect100Continue = false;
System.Web.UI.WebControls.ImageButton app = (System.Web.UI.WebControls.ImageButton)sender;
string ica = proxy.LaunchApplication(app.ToolTip, credentials, Request.UserHostName, Request.UserHostAddress);
Response.ContentType = "application/x-ica";
Response.BinaryWrite(Response.ContentEncoding.GetBytes(ica</place /></city />) );
Response.End();
}
References: