![]() |
Table of Contents
C#IntroductionC# is the primary programming language of the .NET framework. See our .NET tutorial for an overview of the features of the .NET platform and the development environments. In this tutorial we look at how to use the EBI Web Services with C# in the Microsoft .NET SDK and Mono development environments. Microsoft .NET SDK and MonoCreate Service Stubs
From the service WSDL (e.g. http://www.ebi.ac.uk/ws/services/WSDbfetch?wsdl) generate stub classes using the wsdl "http://www.ebi.ac.uk/ws/services/WSDbfetch?wsdl" Use ServiceThen in the program create an instance of the service object: WSDBFetchServerService Dbfetch = new WSDBFetchServerService();
This object provides methods corresponding to those defined in the WSDL so to call the string result = Dbfetch.fetchData("UNIPROT:ADH1A_HUMAN", "default", "raw");
The Console.Write(result); Compile Program
Once the program has been completed, it need to be compiled. This is slightly different depending on the chosen environment. Assuming the program is in a file called Microsoft .NET SDKcsc wsdbfetch.cs WSDBFetchServerService.cs Monomcs wsdbfetch.cs WSDBFetchServerService.cs -r:System.Web.Services Run the Program
The resulting MS Windows, assuming the .NET runtime is installed: wsdbfetch.exe Non-Windows Mono environments: mono wsdbfetch.exe Note: some non-Windows environments (e.g. Linux) can be configured to support direct execution of .NET programs, allowing the use of the Windows style method. Using Data Structures
The methods in the WSDbfetch service all use simple string parameters. Many of the other EBI services use more complex input structures. For example WSInterProScan requires a structure containing the various parameters and the input sequence to be passed to the // The input parameters inputParams input = new inputParams(); // Set the required parameters input.email = "your@email"; // User e-mail address input.async = true; // Async submission input.seqtype = "p"; // Protein input sequence input.crc = true; // Use IprMatches lookup // The input data data[] content = new data[1]; content[0] = new data(); // Input type content[0].type = "seqeunce"; // Input data content[0].content = @">Q8E5Q5_STRA3 MKLSKRYRFWQKVIKALGVLALIATLVLVVYLYKLGILNDSNELKDLVHKYEFWGPMIFI VAQIVQIVFPVIPGGVTTVAGFLIFGPTLGFIYNYIGIIIGSVILFWLVKFYGRKFVLLF MDQKTFDKYESKLETSGYEKFFIFCMASPISPADIMVMITGLSNMSIKRFVTIIMITKPI SIIGYSYLWIYGGDILKNFLN"; // Submit the job WSInterProScanService InterProScan = new WSInterProScanService(); string jobId = InterProScan.runInterProScan(input, content); Console.WriteLine(jobId);
The string status = "PENDING"; // Check status and wait if not finished while(status == "RUNNING" || status == "PENDING") { status = InterProScan.getStatus(jobId); Console.WriteLine(status); if(status == "RUNNING" || status == "PENDING") { // Wait before polling again. System.Threading.Thread.Sleep(15000); } } // Get results Byte[] res = InterProScan.poll(jobId, "toolraw"); // Convert result into a string for output System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding(); string tempStr = enc.GetString(res); // Output the result Console.Write(tempStr); Sample ClientsMost SOAP Web Services at EMBL-EBI have sample clients which provide command-line access to the service and example code. For .NET most of the clients are implemented in C#, for example: Document/literal SOAP
RPC/encoded SOAP
![]() |