integration asp.net application with quickbooks desktop edition - c#

I have an asp.net application and i want to connect it to quickbooks desktop edition , in the web application i want to do the below :
1- get Customers list from quickbooks.
2- create new invoice and save send it to quickbooks.
this is what i found of sample code but i would like to what is the value that i have to set in the AppId parameters in the (sessionManager.BeginSession("", ENOpenMode.omDontCare);).
private void getCustomers()
{
bool sessionBegun = false;
bool connectionOpen = false;
QBSessionManager sessionManager = null;
try
{
//Create the session Manager object
sessionManager = new QBSessionManager();
//Create the message set request object to hold our request
IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 8, 0);
requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
//Connect to QuickBooks and begin a session
sessionManager.OpenConnection(#"D:\A to Z Wholesale Inc.QBW", "QuickBooks Integration Demo");
connectionOpen = true;
sessionManager.BeginSession("", ENOpenMode.omDontCare);
sessionBegun = true;
ICustomerAdd customerAddRq = requestMsgSet.AppendCustomerAddRq();
customerAddRq.Name.SetValue("Amer");
ICustomerQuery customer = requestMsgSet.AppendCustomerQueryRq();
//Send the request and get the response from QuickBooks
IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet);
IResponse response = responseMsgSet.ResponseList.GetAt(0);
ICustomerRet customerRet = (ICustomerRet)response.Detail;
}
catch (Exception ex)
{
}
finally
{
//End the session and close the connection to QuickBooks
if (sessionBegun)
{
sessionManager.EndSession();
}
if (connectionOpen)
{
sessionManager.CloseConnection();
}
}
}

Your approach using COM probably will not work.
The QuickBooks SDK/API is a little stupid in that it uses a Windows COM GUI message pump to do it's dirty work of actually communicating with QuickBooks. That means that a Windows GUI must be present in order for data exchange with QuickBooks to happen.
That's going to be a problem for you, because you're building a web application... which will run inside of IIS, and thus won't have a Windows GUI session available to it.
If you're building a SaaS application, were the goal is to allow multiple other people to connect their QuickBooks files to your web application:
Consider looking at the Intuit Partner Platform/Intuit Anywhere. Be aware that this is only available for SaaS type apps. The basic idea is that people sync their QuickBooks data files up to Intuit's cloud, and then you can use REST web services to exchange data.
Intuit even has some helpful DevKits which provide some sample code and objects/methods to do your data exchange.
Otherwise, if you're not going the Intuit Anywhere route, look at the QuickBooks Web Connector:
The whole point of the QuickBooks Web Connector is to enable integrations like the one you're doing.
Here's a good overview of the QuickBooks Web Connector. It's basically a simple SOAP wrapper around the qbXML schema that QuickBooks understands natively.
If you download the QuickBooks SDK there's some sample code in this folder:
C:\Program Files (x86)\Intuit\IDN\QBSDK12.0\samples\qbdt
There's .NET sample code for the Web Connector in there, which should be helpful.

I recommend you look at #Keith Palmer Jr.'s answer below which much more helpful than this one. I can't delete this one since it was accepted.
Original answer:
I found this webpage: QuickBooks Integration (Mad Computer Scientist)
which says you can use anything:
When opening a connection, you need to specify an application identification ID and name. This will be shown to the user in QuickBooks to allow/disallow the access. These are strings and, so far as I can tell, no checks are run, allowing the user to put anything here that they care to.
The "shown to the user" bit implies you may need to use AutoIt or similar to dismiss a dialog box if you're using this on an ASP.NET server!

Related

Xamarin Android - VpnService is blocking all apps

An app I'm designing uses the VpnService, along with the VpnService.Builder, classes to generate a VPN in order to block traffic from specific apps. According to the documentation over at developer.android.com, all apps should be allowed through the VPN until Builder.AddAllowedApplication or Builder.AddDisallowedApplication is called.
When my VPN service starts up, for some reason, all apps are being disallowed which is strange. As soon as I disconnect from the VPN, all apps become available again. I need to to allow all, unless otherwise specified (which is what the documentation says should be happening). I start the VPN by calling the following:
private string _sTag = typeof(VpnService).Name;
private VpnServiceBinder _objBinder;
private ParcelFileDescriptor _objVpnInterface = null;
private PendingIntent _objPendingIntent = null;
...
if (_objVpnInterface == null)
{
Builder objVpnBuilder = new Builder(this);
objVpnBuilder.AddAddress("10.0.0.2", 32);
objVpnBuilder.AddRoute("0.0.0.0", 0);
// Form the interface
_objVpnInterface = objVpnBuilder.SetSession("Squelch").SetConfigureIntent(_objPendingIntent).Establish();
// Disallow instagram as a test
objVpnBuilder.AddDisallowedApplication("com.instagram.android");
// Set flag
_bVpnIsRunning = true;
}
So in the above instance, instagram should be the only blocked app, but all traffic appears to be blocked (can't use the chrome app, facebook, etc). Is there something I am missing in regards to this? Should I be specifying something before/after establishing the interface? Any help or direction would be greatly appreciated!
Note: In case it matters, I am targeting android 6.0 and higher. I can provide more source if required.
addDisallowedApplication:
By default, all applications are allowed access, except for those denied through this method. Denied applications will use networking as if the VPN wasn't running.
AddDisallowedApplication excludes the application from your VPNService and allows it to continue to use the "non-VPN" networking stack.
addAllowedApplication:
Adds an application that's allowed to access the VPN connection
Note: You can use an allowed or disallowed list, but not both at the same time.
So lets say we want to "block" any Chrome package from accessing the normal networking stack and redirect any Chrome apps from accessing the network via our "blocking" VPN, we can add all Chrome app package names to our VPNService implementation.
Note: there are 4(?) different Chrome apps, alpha, beta, etc.... so lets just block any package that has the name chrome in it, not really ideal, but for an example it works.
using (var pm = Application.Context.PackageManager)
{
var packageList = pm.GetInstalledPackages(0);
foreach (var package in packageList)
{
if (package.PackageName.Contains("chrome"))
{
Log.Debug(TAG, package.PackageName);
builder.AddAllowedApplication(package.PackageName);
}
}
}
After you .Establish() the VPN connection, all Chrome applications networking will be redirected to your VPNService and thus blocked.

How to connect to SQL server database from a Windows 10 UWP app

I'm trying to connect to an on-prem MS SQL database from a universal windows app. I'm making a LOB app using UWP, to support desktop, tablet and mobile use. When trying to connect to a local (intranet) SQL server database, I'm used to using an instance of SqlConnection to connect to a local server, but since SqlConnection is not included in the .NET subset used in UWP, how is this done when using UWP?
I've looked over the official Microsoft samples as well as the how-to guides, and found nothing there about database connection that is not an Azure database. DbConnection seemed like it could be a good way to go, but can't be used since it's abstract, and it's children (for instance Data.SqlClient.SqlConnection) does not seem to be included in the .NET subset for UWP.
Am I missing something super obvious here? As an aside, does anyone know a good namespace reference for UWP?
Edit for non-duplicate: The linked question suggested as a duplicate is for Windows 8/8.1 apps, and while there are some similarities, the code in the accepted answer for that question won't work on UWP. The principle is the same, however, but there should be a better technical reference for Windows 10 apps build with UWP.
With the Windows 10 Fall Creators Update (build 16299) UWP apps can now access SQL Server directly via the standard NET classes (System.Data.SqlClient) - thanks to the newly added support for .NET Standard 2.0 in UWP.
Here is a Northwind UWP demo app:
https://github.com/StefanWickDev/IgniteDemos
We have presented this demo at Microsoft Ignite in September 2017, here is the recording of our session (skip to 23:00 for the SQL demo):
https://myignite.microsoft.com/sessions/53541
Here is the code to retrieve the products from the Northwind database (see DataHelper.cs in the demo). Note that it is exactly the same code that you would write for a Winforms or WPF app - thanks to the .NET Standard 2.0:
public static ProductList GetProducts(string connectionString)
{
const string GetProductsQuery = "select ProductID, ProductName, QuantityPerUnit," +
" UnitPrice, UnitsInStock, Products.CategoryID " +
" from Products inner join Categories on Products.CategoryID = Categories.CategoryID " +
" where Discontinued = 0";
var products = new ProductList();
try
{
using (SqlConnection conn = new SqlConnection(connectionString))
{
conn.Open();
if (conn.State == System.Data.ConnectionState.Open)
{
using (SqlCommand cmd = conn.CreateCommand())
{
cmd.CommandText = GetProductsQuery;
using (SqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
var product = new Product();
product.ProductID = reader.GetInt32(0);
product.ProductName = reader.GetString(1);
product.QuantityPerUnit = reader.GetString(2);
product.UnitPrice = reader.GetDecimal(3);
product.UnitsInStock = reader.GetInt16(4);
product.CategoryId = reader.GetInt32(5);
products.Add(product);
}
}
}
}
}
return products;
}
catch (Exception eSql)
{
Debug.WriteLine("Exception: " + eSql.Message);
}
return null;
}
If you need to support earlier versions than the Fall Creators Update, there is also a way for you to call SqlClient APIs from your UWP app package, via the Desktop Bridge. I have a sample for this published here:
https://github.com/Microsoft/DesktopBridgeToUWP-Samples/tree/master/Samples/SQLServer
Here is a simple sample and a video. Not sure if it's enough for you.
Here is a difficult point is
how to consume, serialize and deserialize json data. As a .net developer, you can consider using the HttpClient to implement this. And here is another sample and video for your reference. There is another official sample shows how to use Windows.Data.Json namespace.
I am having to go down this same road as well... Looking forward to SQLServer being directly accessible via EF Core directly.
I have watched both tutorials above and since I'm new to developing, it only wet my appetite. I did however find this detailed Video Tutorial on YouTube that walks you thru;
creating the WebService
creating duplicated POGO classes in WebService and your UWP App
creating Web API 2.0 Entity Framework Controllers for each Table you want to create
Adding Newtonsoft.JSON and Microsoft.Net.HTTP via NuGet to your UWP App
and finally making calls from UWP back to Local SQL Server via Web Service / JSON calls in Code Behind.
Despite this Video NOT being in English, I was able to watch what he was doing then pause and duplicate.
Connecting UWP to SQL Server
Note: From windows 10 Fall Creators Update (16299) we can directly access SQL Server database using .NetStanded 2.0
As there is no direct way to connect to SQL Server, we need to create an API for our database in order to connect to SQL Server.
This solution describes
Creating API
Serialize and Deserialize JSON data
1. Creating API
1) Installing ASP.NET and web development
Launch Visual Studio Installer and click Modify
Install ASP.NET and web development
2) Creating new ASP.NET Web Application (.Net Framework)
Add new project in your solution
Select ASP.NET Web Application (.Net Framework) and give a project name
Select Web API and click OK
3) Connecting to SQL Server database
Add new item in Models folder
Select ADO.NET Entity Data Model and give it a name
Select EF Designer from database and click Next
Click New Connection
Configure your connection, click OK and click Next
Select Entity Framework version and click next
Select Databases and Tables to be connected and Click Finish
4) Add Controllers to communicate with models
Rebuild your project before doing forther
Add new Controller in Controllers folder
Select Web API 2 Controller with actions, using Entity Framework and click Add
Select Model class (table name) and Data context class (database name) from the drop-down list box and click Add
5) Testing API
Set this project as the startup project
Run the project in a web browser
Now your browser will open a localhost site. Click API in top
This page shows all the API available from your project
Copy any API link from below and replace it with the "Help" in URI and press Enter. Now you should able to see your data from the SQL Server database
2. Serialize and Deserialize JSON data
1) Install Newtonsoft.Json
2) Deserializing JSON
HttpClient httpClient = new HttpClient();
var jsonReponse = await httpClient.GetStringAsync("http://localhost:xxxxx/api/LogIns");
logInResult = JsonConvert.DeserializeObject<List<LogIn>>(jsonReponse);
You can get the model class from Models
Just create the same class in your UWP project
3) Serializing JSON
var logIn = new Models.LogIn()
{
Username = "username",
Password = "password"
};
var logInJson = JsonConvert.SerializeObject(logIn);
HttpClient httpClient = new HttpClient();
var httpContent = new StringContent(logInJson);
httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
await httpClient.PostAsync("http://localhost:56267/api/LogIns", httpContent);
For more info about JSON Serialization And Deserialization Using JSON.NET Library In C#

LoadAsync doesn't work in windows phone 8 with WCF data service

My friend and I just created a WCF data service and would like to consume it with a Windows Phone 8 client. For the WCF data service part, the OData is proved to work with a windows form project which an do CRUD for the database.
So to get WP8 consume WCF Data Service, we followed the tutorial step by step and downloaded the sample code on the MSDN tutorial
http://msdn.microsoft.com/en-us/library/windows/apps/hh394007(v=vs.105).aspx
However,the examples don't work.There's no display of data from database on the phone.
We find the
Customers.LoadAsync(Query)
under function public void LoadData in MainViewModel Class doesn't load the XML data in :http://services.odata.org/Northwind/Northwind.svc/Customers().
public void LoadData()
        {
            // Instantiate the context and binding collection.
            _context = new NorthwindEntities(_rootUri);
            Customers = new DataServiceCollection<Customer>(_context);
            // Specify an OData query that returns all customers.
            var query = from cust in _context.Customers
                        select cust;
            // Load the customer data.
            Customers.LoadAsync(query);
        }
We modified the function OnCustomerLoaded to display the error message if there's any:
private void OnCustomersLoaded(object sender, LoadCompletedEventArgs e)
{
if (e.Error != null)
{
MessageBox.Show(e.Error.Message+e.Error.InnerException);
}
// Make sure that we load all pages of the Customers feed.
if (Staffs.Continuation != null)
{
Staffs.LoadNextPartialSetAsync();
}
//MessageBox.Show(Staffs.ToString());
IsDataLoaded = true;
}
We get the following error:
We are using VS2012 premium, created Windows Phone 8 with data bind project, using OData 5.0.0.
We have to admit that this error may not be the root cause of the problem, but we can't figure it out since we are new to it. We appreciate if anyone can point out what shall we change to make the example work if this is not the error root.
Thanks so much!!
This looks like your app does not have access to the internet, it probably caused by setting issue of your WP Emulator.
You can first try the built-in internet explorer, and check whether it has internet access. If not, you can go to the Hyper-V configuration page, and try change the network adapter settings, or refer to the following page for detail.

how to make autologin in windows form application when it connects on online database remotely

i am working on a windows form application in which i have to make an autologin window.i want that when user desktop connects with internet, Automatically login must be occur. My Desktop application is connected with online database.
Can Any body tell me that what is the procedure to do that.
Please help me i am stucked badly in that.
Thanks in Advance,
Take a look at the System.Net.NetworkInformation Namespace. In particular the NetworkChange class.
Example:
NetworkChange.NetworkAvailabilityChanged += (sender, networkAvailabilityEventArgs) =>
{
if (networkAvailabilityEventArgs.IsAvailable)
{
// Network is available
// Try to open a database connection
}
else
{
// Network is not available
// Stop trying to open a database connection, or clean up existing connections
}
};
edit
You can also call NetworkInterface.GetIsNetworkAvailable() to get the same information on-demand.
if (NetworkInterface.GetIsNetworkAvailable())
{
// Network is available
// Try to log on
}
else
{
// Network is not available
// Do nothing
}
Keep trying to connect to the database until you don't get any error (or at least you can reach the database).
You could also try telnet-ing the remote port, but you can't be sure there's one (if you use SQL Server it's possible you're using Named pipes or other protocols)

What library do I need to reference for remote connection to RDC server from console app?

We have a terminal server: "server.host.com". Normally, we RDP into that server for our business applications. However, I am performing some datamining and want to bring the .xml files to a local system for post processing.
My utility app would basically log in (impersonating my account), navigate to the directory where the .xml files are stored, then begin copying to a local directory. This utility would be set to run every morning at 3am unattended.
I am trying to determine whether WMI is the correct library, or Remoting, or some other library? Is this even going to be possible?
So if you are looking at using Microsoft's remote desktop, you can add a reference to Microsoft Terminal Services Control Type Library in the COM section. If you are working with a gui, you can just drag the control and do something like:
rdp.Server = txtServ.Text;
rdp.UserName = txtUser.Text;
IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx();
secured.ClearTextPassword = txtPassword.Text;
rdp.Connect();
If you are using the console, should be just as simple just without the buttons and all.

Categories