James Kite

About James Kite

James has served as the Senior Transactional Developer since July 2012, adding more than 15 years of overall IT experience to the Beacon team. He specializes in .Net and Sql Servers and has a strong knowledge of Cascade Server development, as well as Velocity programming. James holds a B.A. in Computer Information Systems from High Point University.
8 07, 2015

SFTP File Retrieval With .Net

By | 2017-06-16T12:26:25+00:00 July 8th, 2015|Categories: Web Development|

I am often tasked with developing .Net applications to interact with FTP servers for uploading and downloading files.  However, I was recently given a project involving file manipulation using SFTP (Secure File Transfer Protocol) and I was at a bit of a loss.  While there are endless online examples of using FTP with .Net, examples using SFTP were much scarcer.

Luckily for me, there is a wonderful SFTP client library specifically for .Net developed by Rebex:  http://www.rebex.net/sftp.net/.  Simply add the Rebex DLL file to your project, add a reference to it, and you’re ready to start accessing files from your application via SFTP.  I found it easier and cleaner to create a wrapper class to interact with the Rebex library.  From there it’s as simple as creating an instance of your wrapper class and downloading your files.  Complete code samples are below:

 

Example of using wrapper class to download file:

Wrapper class:

8 02, 2013

Using .Net ASHX Handlers To Build Web Services

By | 2016-04-21T10:04:11+00:00 February 8th, 2013|Categories: Web Development|Tags: , , , |

I was recently given the task of rewriting an existing web service with a predefined SOAP request and response.  I didn’t have access to the original code to use as a reference point, but it was fairly simple in concept:  Receive an incoming SOAP message, do some processing, and send a SOAP response back to the caller.  Initially, I attempted to use a standard Visual Basic ASMX web service but was unable to get my incoming and outgoing objects to perfectly match the predefined SOAP messages that I was expected to use.  I even tried using Microsoft’s WSDL.exe to reverse engineer the old web service’s WSDL (web service definition language) but still had no luck.

After some head scratching, I finally decided to try a more “brute force” approach using a Microsoft HTTP handler (ASHX) file.  Below is a code sample of accepting an incoming SOAP/XML message with one of these ASHX files and sending a response back to the caller:

As you can see, I am simply taking what is being passed in the input stream and loading it in to an XmlDocument object.  From there I can read the XML and do whatever processing is necessary.  Additionally, I am sending a SOAP response back to the client by simply setting the content type of the response to text/xml and writing out the XML.

By setting up my web service using an HTTP handler, I was able to bypass the mysterious Microsoft “black box” that you encounter when using a standard ASMX to send and receive SOAP messages.  And since this places the incoming and outgoing SOAP messages completely under my control, I am able to easily configure the structure of those messages via code.  So at the end of the day I had a functional, scalable, and easily maintained web service.