FYI - quick steps to read & write data through SOAP interface with C#

Tuesday, January 13, 2015
Avatar
As a community service, here are some quick steps to start using the SOAP interface so that you can programmatically read and write data in your SpiraTeam instance.

These steps are for .NET C#.  These steps supplant the Inflectra knowledge base article "How to access Spira v3.x SOAP web services using C#".  Use at your own risk.

1.  Download and install the free Visual Studio 2013 Express for Windows Desktop.
2.  Through it, start a new project.  Use the template for a Visual C# Console Application project.
3.  Through the menu 'Project', add a service reference.  
For the address, provide the correct URL for your instance's SOAP interface.  It may look something like the following, which is for our hosted instance:  https://edmap.spiraservice.net/Services/v4_0/ImportExport.svc.  
Change the namespace from ServiceReference1 to "SpiraImportExport40".
4.  Replace all the code in your program.cs file with the code after the line below.  
5.  Then, in the program.cs file, do the following:
5a.  On line, 19, replace the EndPoint web address with the appropriate URL for your instance's SOAP interface.  (The same URL you used in step 3.)
5b.  On lines 27 and 32, adjust the key/id fields.  Use a valid project id and a valid release id.
5c.  On line 28, provide your username and password.
6.  If the URL you are using starts with "https" instead of "http", then do the following.
6a.  Through the Edit menu, do a Replace in Files.  Replace "ttpBind" with "ttpsBind" in your entire solution.  Replace All.  (Should be 36 replacements.)
6b.  In the program.cs file on line 24, replace "BasicHttpSecurityMode.None" with "BasicHttpsSecurityMode.Transport".
7.  Build the solution and start it.  Enjoy.

program.cs code:
-------------------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {

            //The following code will connect to Spira, authenticate, connect to a project and then get a list of incidents fixed in a specific release:

            //Instantiate the web-service proxy class and set the URL from the .config file
            SpiraImportExport40.ImportExportClient spiraImportExport = new SpiraImportExport40.ImportExportClient();
            spiraImportExport.Endpoint.Address = new EndpointAddress("http://servername/SpiraTest/Services/v3_0/ImportExport.svc");

            //Configure the HTTP Binding to handle session cookies
            BasicHttpBinding httpBinding = (BasicHttpBinding)spiraImportExport.Endpoint.Binding;
            httpBinding.AllowCookies = true;
            httpBinding.Security.Mode = BasicHttpSecurityMode.None;

            //Next lets authenticate and connect to the project
            int projectId = 1;
            spiraImportExport.Connection_Authenticate("username", "password");
            spiraImportExport.Connection_ConnectToProject(projectId);

            //Now lets get a list of incidents fixed in Release RL00005
            int releaseId = 5;
            List<SpiraImportExport40.RemoteFilter> remoteFilters = new List<SpiraImportExport40.RemoteFilter>();
            SpiraImportExport40.RemoteFilter remoteFilter = new SpiraImportExport40.RemoteFilter();
            remoteFilter.PropertyName = "ResolvedReleaseId";
            remoteFilter.IntValue = releaseId;
            remoteFilters.Add(remoteFilter);
            SpiraImportExport40.RemoteSort remoteSort = new SpiraImportExport40.RemoteSort();
            remoteSort.PropertyName = "Name";
            remoteSort.SortAscending = true;
            SpiraImportExport40.RemoteIncident[] remoteIncidents = spiraImportExport.Incident_Retrieve(remoteFilters.ToArray(), remoteSort, 1, 999999);

            //Loop through and display ID, name and description
            foreach (SpiraImportExport40.RemoteIncident remoteIncident in remoteIncidents)
            {
                Console.WriteLine(remoteIncident.IncidentId + " | " + remoteIncident.Name);
            }        
            Console.WriteLine("");
            Console.Write("Press Enter to Exit...");
            Console.ReadLine();
            spiraImportExport.Connection_Disconnect();
        }
    }
}

2 Replies
Wednesday, January 14, 2015
Avatar
re: jfreed Tuesday, January 13, 2015
Good catch on the namespace, <Message Deleted>.  

New step
5d:  Unless your project name is "ConsoleApplication3 (and it probably isn't), then on line 8, change "ConsoleApplication3" so that it matches the name of your project.

The error regarding BasicHttpBinding versus BasicHttpsBinding was somewhat expected depending on the URL you are using for your instance's SOAP interface.  See my step 6.  However, I'm not sure if that explains what you encountered.  You stated that you're using Visual Studio 2010, but the steps are for VS 2013.  You might try 2013 to see if that resolves any remaining problems.
Thursday, November 8, 2018
Avatar
re: jfreed Monday, February 9, 2015

Thanks for taking the time to write this up. It was very helpful in getting started. We're going to integrate this into our automation build process to create releases in Spira automatically. 

Spira Helps You Deliver Quality Software, Faster and With Lower Risk

And if you have any questions, please email or call us at +1 (202) 558-6885

 

Statistics
  • Started: Tuesday, January 13, 2015
  • Last Reply: Thursday, November 8, 2018
  • Replies: 2
  • Views: 11072