0

I currently have a visual basic console application that runs on the server nightly and that has several classes. Each class has lots of properties as well as quite a few procedures and functions doing various tasks.

I have a payer class that handles information and functions dealing with payers, a recipient class that handles information and functions dealing with recipients and I have a payment class that holds information about payments. Two of the payment class properties are of payer type and recipient type. Part of my application creates a PDF out of all of this information and faxes it to the recipient.

Now I also have a asp.net website that displays information about all of these payers, recipients, and payments. Currently it does not access anything the console application has. It just gets information from the database and displays it in various list views and things.

The client is now asking to have a button on the website that would allow them to recreate the pdf that the console application currently generates. There is a lot of code involved in this and I need a way to not duplicate it.

My thought was to make a webservice that handles creating the pdf and both the application and the website could call it. But the web service will need access to these custom classes that currently live in my console application.

What would be the best way for both my webservice and the console application to have access to these classes. Would it then be possible to pass a custom object of type payment as a parameter to the webservice?

E Arnold
  • 3
  • 1
  • possible duplicate of [How do you share code between projects/solutions in Visual Studio?](http://stackoverflow.com/questions/1116465/how-do-you-share-code-between-projects-solutions-in-visual-studio) – jrummell Sep 17 '14 at 18:27

1 Answers1

1

Using a class library

I had a similar situation where I had to share some classes and functions between projects. What I did was to create a Class Library and put those classes there. Also, when I created the library I had some issues with namespaces so I had some rewriting to do on that part.

So, essentially my solution was separated in two projects

  1. The core library (class library)
  2. The website (ASP.NET web application)

In the core library I had all code regarding the Data Access Layer, all the entity classes of my application and a bunch of helper classes, tools etc while in the website I did not leave much code except from the code involved in the pages and user controls.

With this approach you will have an extra .dll file containing the shared classes that the console application, the webservice and the web application will share.

Keep in mind that there are some things that you need to keep in mind such as the connection string where each application might store it in a different place. Also you cannot use the Request, Response, Server etc namespaces in your library since it will be null in the case of the desktop application.

Using linked files

An other way to share code between projects is to have the code files in one project and link those files to the other.

Right click in your project and choose Add -> Existing item, and then click the down arrow next to the Add button and select Add as link:

Finally this thread is about this subject, so it might be useful.

Community
  • 1
  • 1
Tasos K.
  • 7,979
  • 7
  • 39
  • 63