You are here: Chapter 11: FootPrints API > FootPrints Web Services API > Sample Code > C# Sample

C# Sample

Creating an Issue

using System;

[

    System.Web.Services.WebServiceBindingAttribute(

        Name="CreateIssueWebService",

        Namespace="MRWebServices"

    )

]

public class CreateIssue : System.Web.Services.Protocols.SoapHttpClientProtocol

{

    public CreateIssue()

    {

        this.Url = "http://fakeserver/MRcgi/MRWebServices.pl";

        

        // Comment this out if not using a proxy server.

        //System.Net.IWebProxy proxyObject = new System.Net.WebProxy("http://localhost:8888/", false);

        //this.Proxy = proxyObject;

    }

    [

        System.Web.Services.Protocols.SoapDocumentMethodAttribute(

            "MRWebServices#MRWebServices__createIssue",

            RequestNamespace="MRWebServices",

            ResponseNamespace="MRWebServices",

            Use=System.Web.Services.Description.SoapBindingUse.Encoded,

            ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped

        )

    ]

    [return: System.Xml.Serialization.SoapElementAttribute("return")]

    public string MRWebServices__createIssue(

        string usr,

        string pw,

        string extraInfo,

        CreateIssueArgs args

    )

    {

        object[] results = this.Invoke(

            "MRWebServices__createIssue",

            new object[] {usr, pw, extraInfo, args }

        );

        return ((string)(results[0]));

    }

}

[System.Xml.Serialization.SoapTypeAttribute("ABFields", "MRWebServices")]

public class ABFields

{

    public string Last__bName;

    public string First__bName;

    public string Email__baddress;

    public string Custom__bAB__bField__bOne;

}

[System.Xml.Serialization.SoapTypeAttribute("ProjFields", "MRWebServices")]

public class ProjFields

{

    public string Custom__bField__bOne;

    public string Custom__bField__bTwo;

}

[System.Xml.Serialization.SoapTypeAttribute("CreateIssueArgs", "MRWebServices")]

public class CreateIssueArgs

{

    public string projectID;

    public string title;

    public string [] assignees;

    public string priorityNumber;

    public string status;

    public string description;

    public ABFields abfields;

    public ProjFields projfields;

}

class main

{

    [STAThread]

    static void Main()

    {

        CreateIssue issue = new CreateIssue();

        ABFields abFields = new ABFields();

        abFields.Last__bName = "Doe";

        abFields.First__bName = "John";

        abFields.Email__baddress = "[email protected]";

        abFields.Custom__bAB__bField__bOne = "Value of Custom AB Field One";

        ProjFields projFields = new ProjFields();

        projFields.Custom__bField__bOne = "Value of Custom Field One";

        projFields.Custom__bField__bTwo = "Value of Custom Field Two";

        CreateIssueArgs issueargs = new CreateIssueArgs();

        issueargs.projectID = "78";

        issueargs.title = "Place title of new issue here.";

        issueargs.assignees = new string [] { "user1", "user2" };

        issueargs.priorityNumber = "1";

        issueargs.status = "Open";

        issueargs.description = "Place issue description here.\nFrom C# code.";

        issueargs.abfields = abFields;

        issueargs.projfields = projFields;

        string result = issue.MRWebServices__createIssue(

            "WebServices",

            "fakepassword",

            "",

            issueargs

        );

        Console.WriteLine( "Issue " + result + " has been created.\n" );

    }

}

Editing an Issue

using System;

[

    System.Web.Services.WebServiceBindingAttribute(

        Name="EditIssueWebService",

        Namespace="MRWebServices"

    )

]

public class EditIssue : System.Web.Services.Protocols.SoapHttpClientProtocol

{

    public EditIssue()

    {

        this.Url = "http://fakeserver/MRcgi/MRWebServices.pl";

        // Comment this out if not using a proxy server.

        //System.Net.IWebProxy proxyObject = new System.Net.WebProxy("http://localhost:8888/", false);

        //this.Proxy = proxyObject;

    }

    [

        System.Web.Services.Protocols.SoapDocumentMethodAttribute(

            "MRWebServices#MRWebServices__editIssue",

            RequestNamespace="MRWebServices",

            ResponseNamespace="MRWebServices",

            Use=System.Web.Services.Description.SoapBindingUse.Encoded,

            ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped

        )

    ]

    [return: System.Xml.Serialization.SoapElementAttribute("return")]

    public void MRWebServices__editIssue(

        string usr,

        string pw,

        string extraInfo,

        EditIssueArgs args

    )

    {

        object[] results = this.Invoke(

            "MRWebServices__editIssue",

            new object[] {usr, pw, extraInfo, args }

        );

    }

}

[System.Xml.Serialization.SoapTypeAttribute("ABFields", "MRWebServices")]

public class ABFields

{

    public string Custom__bAB__bField__bOne;

}

[System.Xml.Serialization.SoapTypeAttribute("ProjFields", "MRWebServices")]

public class ProjFields

{

    public string Custom__bField__bTwo;

}

[System.Xml.Serialization.SoapTypeAttribute("CreateIssueArgs", "MRWebServices")]

public class EditIssueArgs

{

    public string projectID;

    public string mrID;

    public string title;

    public ABFields abfields;

    public ProjFields projfields;

}

class main

{

    [STAThread]

    static void Main()

    {

        EditIssue issue = new EditIssue();

        ABFields abFields = new ABFields();

        abFields.Custom__bAB__bField__bOne = "NEW VALUE FOR Custom AB Field One";

        ProjFields projFields = new ProjFields();

        projFields.Custom__bField__bTwo = "NEW VALUE FOR Custom Field Two";

        EditIssueArgs issueargs = new EditIssueArgs();

        issueargs.projectID = "78";

        issueargs.mrID = "11";

        issueargs.title = "NEW title is here.";

        issueargs.abfields = abFields;

        issueargs.projfields = projFields;

        issue.MRWebServices__editIssue(

            "WebServices",

            "fakepassword",

            "",

            issueargs

        );

        Console.WriteLine( "done" );

    }

}

Retrieving Issue Details

using System;

using System.IO;

using System.Xml;

[

System.Web.Services.WebServiceBindingAttribute(

    Name="GetIssueDetailsWebService",

    Namespace="MRWebServices" )

]

public class GetIssueDetails : System.Web.Services.Protocols.SoapHttpClientProtocol

{

    public GetIssueDetails()

    {

        this.Url = "http://fakeserver/MRcgi/MRWebServices.pl";

        // Comment out if not using a proxy server.

        System.Net.IWebProxy proxyObject = new System.Net.WebProxy("http://localhost:8888/", false);

        this.Proxy = proxyObject;

    }

    [

    System.Web.Services.Protocols.SoapDocumentMethodAttribute(

        "MRWebServices#MRWebServices__getIssueDetails",

        RequestNamespace="MRWebServices",

        ResponseNamespace="MRWebServices",

        Use=System.Web.Services.Description.SoapBindingUse.Encoded,

        ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped

        )

    ]

    [return: System.Xml.Serialization.SoapElementAttribute("return")]

    public byte[] MRWebServices__getIssueDetails(

        string usr,

        string pw,

        string extraInfo,

        int proj,

        int num,

        int api)

    {

        object[] results = this.Invoke(

            "MRWebServices__getIssueDetails",

            new object[] {usr, pw, extraInfo, proj, num, api} );

        return ((byte[])(results[0]));

    }

}

class main

{

    private static void ParseXml( XmlReader reader )

    {

        while( reader.Read() )

        {

            switch( reader.NodeType )

            {

                case XmlNodeType.Element:

  

                    while( reader.MoveToNextAttribute() )

                    {

                        if( reader.Name == "key" && reader.Value == "title" )

                        {

                            reader.Read();

                            Console.WriteLine( "Title: " + reader.Value );                      

                        }

                        else if( reader.Name == "key" && reader.Value == "mr" )

                        {

                            reader.Read();

                            Console.WriteLine( "Issue Number: " + reader.Value );                      

                        }

                        else if( reader.Name == "key" && reader.Value == "status" )

                        {

                            reader.Read();

                            Console.WriteLine( "Issue Status: " + reader.Value );                      

                        }

                    }

                    break;

            }

        }

    }

    [STAThread]

    static void Main()

    {

        System.IO.StringReader stream = null;

        System.Xml.XmlTextReader reader = null;

        try

        {

            GetIssueDetails obj = new GetIssueDetails();

            byte[] resultBytes = obj.MRWebServices__getIssueDetails(

                "WebServices",

                "fakepassword",

                "RETURN_MODE => 'xml'",

                12,

                20047,

                2 ); //The number 2 should be hard coded.

            //The below coding line may assume FootPrints is using,

            //UTF8. If using a different local encoding, you may need

            //to chahge the line to (example assumes Windows-1252):

            

            //System.Text.Encoding encoding =

            //    System.Text.GetEncoding(1252);

            System.Text.Encoding encoding = System.Text.Encoding.UTF8;

            

            //In addition to replacing the above encoding line, if

            //using a different encoding and saving data to

            //FootPrints, you will need to place a line in your

            //MRlocalDefs file with the following information (this

            //also assumes Windows-1252):

            

            //$FP::WEB_SERVICES_ENCODING = 'cp1252';

            string result = encoding.GetString(resultBytes);

        

            Console.WriteLine( "XML RESULT:\n-----------\n" + result );

            Console.WriteLine( "PARSING RESULT:\n---------------" );   

            stream = new System.IO.StringReader( result );

            reader = new System.Xml.XmlTextReader( stream );

            ParseXml( reader );

        }

        catch( Exception e )

        {

            Console.WriteLine ("Exception: {0}", e.ToString());

        }

        finally

        {

            if( reader != null )

            {

                reader.Close();

            }

        }

    }

}

Querying the FootPrints Database

using System;

using System.IO;

using System.Xml;

[

    System.Web.Services.WebServiceBindingAttribute(

        Name="SearchWebService",

        Namespace="MRWebServices"

    )

]

public class Search : System.Web.Services.Protocols.SoapHttpClientProtocol

{

    public Search()

    {

        this.Url = "http://fakeserver/MRcgi/MRWebServices.pl";

        

        // Comment out if not using a proxy server.

        System.Net.IWebProxy proxyObject = new System.Net.WebProxy("http://localhost:8888/", false);

        this.Proxy = proxyObject;

    }

    [

        System.Web.Services.Protocols.SoapDocumentMethodAttribute(

            "MRWebServices#MRWebServices__search",

            RequestNamespace="MRWebServices",

            ResponseNamespace="MRWebServices",

            Use=System.Web.Services.Description.SoapBindingUse.Encoded,

            ParameterStyle=System.Web.Services.Protocols.SoapParameterStyle.Wrapped

        )

    ]

    [return: System.Xml.Serialization.SoapElementAttribute("return")]

    public byte[] MRWebServices__search(

        string usr,

        string pw,

        string extraInfo,

        string query,

        int api

    )

    {

        object[] results = this.Invoke(

            "MRWebServices__search",

            new object[] {usr, pw, extraInfo, query, api} );

        return ((byte[])(results[0]));

    }

}

class main

{

    private static void ParseXml( XmlReader reader )

    {

        while( reader.Read() )

        {

            switch( reader.NodeType )

            {

                case XmlNodeType.Element:

  

                    while( reader.MoveToNextAttribute() )

                    {

                        if( reader.Name == "key" && reader.Value == "mrtitle" )

                        {

                            reader.Read();

                            Console.WriteLine( "Title: " + reader.Value );                      

                        }

                        else if( reader.Name == "key" && reader.Value == "mrid" )

                        {

                            reader.Read();

                            Console.WriteLine( "Issue Number: " + reader.Value );                      

                        }

                    }

                    break;

            }

        }

    }

    [STAThread]

    static void Main()

    {

        System.IO.StringReader stream = null;

        System.Xml.XmlTextReader reader = null;

        try

        {

            Search search = new Search();

            byte[] resultBytes = search.MRWebServices__search(

                "WebServices",

                "fakepassword",

                "RETURN_MODE => 'xml'",

               "SELECT MASTER12.mrID, mrPRIORITY, mrASSIGNEES, mrUPDATEDATE, mrSTATUS, mrTITLE, mrURGENT,

                    mrSUBMITTER, mrATTACHMENTS, First__bName, Last__bName

                    from MASTER12 inner join MASTER12_ABDATA on MASTER12.MRID = MASTER12_ABDATA.MRID

                    WHERE mrSTATUS <> '_DELETED_' and ( ( ( (mrTITLE LIKE '%.Net%'

                    or (CONTAINS(MASTER12.*, '\"*.Net*\"')) or Platform LIKE '%__dNet%'

                    or Product LIKE '%__dNet%' or request__btype LIKE '%__dNet%'

                    or Projected__brelease LIKE '%__dNet%' or FootPrints__bfeature LIKE '%__dNet%'

                    or DB LIKE '%__dNet%' or Complexity LIKE '%__dNet%' or Current__bversion LIKE '%__dNet%'

                    or Was__b5__d5__d1 LIKE '%__dNet%' or LocalDefs__bVariable LIKE '%.Net%'

                    or Customer__bpatch__Q LIKE '%__dNet%' or Not__bin__bGDBM__Q LIKE '%__dNet%'

                    or Tester__bAssigned LIKE '%__dNet%' or Alpha__b1__bVerified LIKE '%__dNet%'

                    or Fixed__bin LIKE '%__dNet%' or Alpha__b2__bVerified LIKE '%__dNet%'

                    or Alpha__b3__bVerified LIKE '%__dNet%' or Multi__bSelect__bField LIKE '%__dNet%'

                    or DateTime__bField__bLink LIKE '%.Net%' or SLA LIKE '%__dNet%'

                    or Last__bName LIKE '%.Net%' or First__bName LIKE '%.Net%'

                    or Email__baddress LIKE '%.Net%' or Company LIKE '%.Net%' or Phone LIKE '%.Net%'

                    or Customer__bstatus LIKE '%__dNet%' or Salesperson LIKE '%__dNet%'

                    or Country LIKE '%.Net%' or on__bor__boff LIKE '%__dNet%') ) ) )

                    order by MASTER12.mrID DESC",

                    2); //The number 2 should be hard coded

                // The below encoding line may assumes FootPrints is using

                // UTF8. If using a different local encoding, you may need

                // to change the line to (example assumes Windows-1252):

 

                // System.Text.Encoding encoding =

                // System.Text.GetEncoding(1252);

                System.Text.Encoding encoding = System.Text.Encoding.UTF8;

 

                // In addition to replacing the above encoding line, if

                // using a different encoding and saving data to

                // FootPrints, you will need to place a line in your

                // MRlocalDefs file with the following information (this

                // also assumes Windows-1252):

 

                // $FP::WEB_SERVICES_ENCODING = 'cp1252';

                string result = encoding.GetString(resultBytes);

 

            Console.WriteLine( "XML RESULT:\n-----------\n" + result );

            Console.WriteLine( "PARSING RESULT:\n---------------" );   

            stream = new System.IO.StringReader( result );

            reader = new System.Xml.XmlTextReader( stream );

            ParseXml( reader );

        }

        catch( Exception e )

        {

            Console.WriteLine ("Exception: {0}", e.ToString());

        }

        finally

        {

            if( reader != null )

            {

                reader.Close();

            }

        }

    }

}