Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Calling web service using ASP.NET

, 27 Dec 2007
show how to call a web services inside ASP.NET web project. using a test published web services; Extentrix Web Services 2.0 Application Edition
webserviceconsumer.zip
WebServiceConsumer
App_Data
App_WebReferences
ExtentrixWS
ExtentrixWebServicesForCPS.disco
ExtentrixWebServicesForCPS.discomap
ExtentrixWebServicesForCPS.wsdl
/*--------------------------------------------------------------------------*
 *  Copyright (C) 2007 Extentrix Systems
 *
 *  File:      Default.aspx.cs
 *
 *  Contents:  It is an example on how to consume Extentrix Web Services 2.0 � Application Edition
 *--------------------------------------------------------------------------*/

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ExtentrixWS;
using System.Net;
using System.Windows.Forms;
using System.IO;

public partial class _Default : System.Web.UI.Page 
{
    //define a web service proxy object.
    private ExtentrixWS.ExtentrixWebServicesForCPS proxy;
    
    //define a Citrix Presentation Server Credentials object.
    private Credentials credentials;

    protected void Page_Load(object sender, EventArgs e)
    {
        //When using the HttpWebRequest to POST form data using HTTP 1.1,
        //it ALWAYS adds the following HTTP header "Expect: 100-Continue". 
        //Fixing the problem set it to false.
        ServicePointManager.Expect100Continue = false;

        //intialaize objects
         proxy = new ExtentrixWebServicesForCPS();
         credentials = new Credentials();

        //set credentials
        //these values are according to Citrix testdrive presentation server
        //that Extentrix published a web service for it for deloveper to use it
        //as a test web service.

        credentials.Password = "demo";
        credentials.UserName = "citrixdesktop";
        credentials.Domain = "testdrive";
        
        //because it is a sample and we will use no encryption methode
        //so the password will send as a clear text.
        credentials.PasswordEncryptionMethod = 0;
        
        //set the domain type to windows domain
        credentials.DomainType = 0;


        // 1) Get all the published applications list by calling GetApplicationsByCredentialsEx web service.
        // 2) create an ImageButton for each application
        // 3) Create Image for the application 
        // 4) Add it to the AppList panel.
        // 5) Set the event handler for each ImageButton, so when clicking it the associated application will run

        //calling the web service
        ApplicationItemEx[] items = proxy.GetApplicationsByCredentialsEx(credentials, Request.UserHostName, Request.UserHostAddress, new string[] { "icon","icon-info" }, new string[] { "all" }, new string[] { "all" });

        //loop for each published application
        for (int i = 0; i < items.Length; i++) {
            //create the ImageButton
            System.Web.UI.WebControls.ImageButton app = new System.Web.UI.WebControls.ImageButton();
            
            //set the Image URL to the created image
            app.ImageUrl = createIcon(items[i].InternalName,items[i].Icon);

            //set the ToolTip to the name of the published application
            app.ToolTip = items[i].InternalName;

            //add the ImageButton to the AppList panel
            AppList.Controls.Add(app);

            //set the event handler for the ImageButton.
            app.Click += new System.Web.UI.ImageClickEventHandler(this.OnApplicationClicked);
            
        }
        

    }

    private void OnApplicationClicked (object sender, System.EventArgs e)
    {
        // Get the event source object.
        System.Web.UI.WebControls.ImageButton app = (System.Web.UI.WebControls.ImageButton)sender;

        ServicePointManager.Expect100Continue = false;

        //Get the ICA file content by calling LaunchApplication web service.
        string ica = proxy.LaunchApplication(app.ToolTip, credentials, Request.UserHostName, Request.UserHostAddress);

        //Set the response content type to "application/x-ica" to run the ICA file.
        Response.ContentType = "application/x-ica";

        //Run the application by writing the ICA file content to the response.
        Response.BinaryWrite(Response.ContentEncoding.GetBytes(ica));
        Response.End();
    }



    public static String createIcon(String iconName, String iconData)
    {
        
        //Save the published application icon to file.
        // 1)Get the encoded bytes from the icon data string
        // 2) write the bytes to a file stream.

        try
        {
            //Get the encoded byte array
            byte[] bimg = System.Convert.FromBase64String(iconData);

            //change the path according to your system.
            string path = "c:/Extentrix/" + iconName + ".gif";


            //write the icon bytes to a file.
            FileStream fStream = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
            BinaryWriter stream = new BinaryWriter(fStream);
            stream.Write(bimg);
            stream.Close();
            fStream.Close();

            return path;

        }
        catch (Exception exc)
        {

        }
        return "";
    }

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Asya Alshaikh
Software Developer Extentrix Systems
Jordan Jordan
No Biography provided

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 27 Dec 2007
Article Copyright 2007 by Asya Alshaikh
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid