I'm having hard times importing a C# Dll into another simple test application (console, winform, you name it).
Basically it consist in a huge library which consumes the European Community Vat checking service (which URL I believe is Vat webservice.
The service makes you download a library, then the implementation of the code is up to you.
What I did is starting a new C# class library in Visual studio 2010 and then adding this class which is automatically downloaded from the webservice for your own use, and then wrote this snippet I found in the web.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Xml; using System.IO; namespace EuroVAT { public class EuroVAT { public static Array check(string country, string vatNum) { bool valid; string name; string address; checkVatService vatchecker = new checkVatService(); vatchecker.checkVat(ref country, ref vatNum, out valid, out name, out address); return new object[] {country, vatNum, valid, name, address }; } } } Well, when I create a new Console application, then add a reference (right click on project name, add reference, browse to the dll) to my DLL compiled from a Class Library project which included the 2 classes I linked/quoted up here.
Here's some code I tried to use my dll:
using EuroVAT; namespace DLLTEST { class Program { static void Main(string[] args) { EuroVat test = new EuroVat(); } } } Basically I am not able to call them from the program. All I get when I try to call EuroVAT object is
Error 1 The type or namespace name 'EuroVAT' could not be found (are you missing a using directive or an assembly reference?)
I tried to build, close, reopen project. Tried to put it in Winforms and so on to no avail. I always get that error.
What am I doing wrong? What can I do to solve it?
One more question:
What exactly this code is doing?
return new object[] {country, vatNum, valid, name, address }; It's like returning an array of objects? Because when I run the program all the output is thrown out all togheter. Usually I have to cycle throught the output with some sort of loop...
Last question, if someone can help:
I'll have to include this DLL in a SQL server (2008 I think)
I have read about the subject and discovered that for passing values to SQL Server from a C# dll you have to include various libraries and declare your methods as SqlProcedures, but also passing/retrieving your values as SqlTypes (SqlInt32, SqlString, etc etc).
Here's what I came up with:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Xml; using System.IO; using System.Data; using System.Data.SqlClient; using System.Data.SqlTypes; using Microsoft.SqlServer.Server; namespace WebServiceVatEuropa { class Program { [SqlProcedure] public static Array check(string country, string vatNum) { bool valid; string name; string address; checkVatService vatchecker = new checkVatService(); vatchecker.checkVat(ref country, ref vatNum, out valid, out name, out address); return new object[] {country, vatNum, valid, name, address }; } } } I hope it's correct. What I'm missing is how I can cast all those object to SqlTypes like SqlInt32, SqlString and so on. I tried but I got tons of conversion errors and stuff like that. It just won't allow me to declare those objects ad SqlTypes and I can't work out the last to make the last return statement to output those SqlTypes.
Can anyone show an example if possible?
Thank you all.