Solved

C# Web Services Compilation Error

Posted on 2014-04-04
7
408 Views
Last Modified: 2014-07-22
I created a webservice that works fine on my local machine. However when I upload it to my host I get this error:

Compiler Error Message: CS0246: The type or namespace name 'BL' could not be found (are you missing a using directive or an assembly reference?)

Here is the code
<%@ WebService Language="C#" Class="budget" %>

using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Web.SessionState;
using System.Data.SqlClient;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;
using System.Collections.Generic;
using System.Linq;
using System.Web.Script.Serialization;
using System.IO;
using System.Text.RegularExpressions;
using System.Text;
using System.Net.Mail;

/// <summary>
/// Summary description for data
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

[System.Web.Script.Services.ScriptService]
public class budget : System.Web.Services.WebService {

    public budget() {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    protected BL BalAccess
    {
        get
        {
            BL BalAccess = new BL();
            return BalAccess;
        }
    }

    public string GetJson(DataTable dt)
    {
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        serializer.MaxJsonLength = Int32.MaxValue;
        List<Dictionary<string, object>> rows = new List<Dictionary<string, object>>();
        Dictionary<string, object> row = null;

        foreach (DataRow dr in dt.Rows)
        {
            row = new Dictionary<string, object>();
            foreach (DataColumn col in dt.Columns)
            {
                row.Add(col.ColumnName, dr[col]);
            }
            rows.Add(row);
        }
        return serializer.Serialize(rows);
    }

    [WebMethod]
    public string jSelect(string TableName, string Fields, string Condition)
    {
        string sJSON = "";

        DataTable dt = new DataTable();
        dt = BalAccess.Select(TableName, Fields, Condition);

        int dtCount = dt.Rows.Count;

        if (dtCount > 0)
        {
            sJSON = GetJson(dt);
            sJSON = sJSON.Replace("null", "[]");

        }

        return sJSON;
    }
    
}

Open in new window

0
Comment
Question by:quest_capital
  • 3
  • 2
  • 2
7 Comments
 
LVL 15

Expert Comment

by:Minh Võ Công
ID: 39979509
how define BL class?
0
 

Author Comment

by:quest_capital
ID: 39979516
Here is the BL Class
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

/// <summary>
/// Summary description for BL
/// </summary>
public class BL
{
	public BL()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public DataTable Select(string Table, string Fields, string Condition)
    {
        DS DS = new DS();
        try
        {
            return DS.Select(Table, Fields, Condition);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            DS = null;
        }

    }
}

Open in new window

0
 
LVL 15

Expert Comment

by:Minh Võ Công
ID: 39979526
you can check you reference file

<%@ Assembly Name="MyAssembly" %>
or
<%@ Assembly Src="path/myFile.cs" %>

http://stackoverflow.com/questions/10918947/how-to-reference-a-custom-dll-from-an-uncompiled-net-webservice
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 12

Expert Comment

by:jitendra patil
ID: 39979663
the error says, you are missing a reference to your BL class, you need to have BL class dll on the iis server in the bin folder, where your webservice is hosted.

hope this helps.
0
 

Author Comment

by:quest_capital
ID: 39980015
jitendra patil

This my be a stupid question but my BL.cs is in my App_Code folder there is no dll made.
Wouldn't there be one made when I run the website?
0
 

Author Comment

by:quest_capital
ID: 39980088
I deployed the web site an I got the dll for the App_Code folder but I still get the same error.
0
 
LVL 12

Accepted Solution

by:
jitendra patil earned 500 total points
ID: 39980922
have you checked the dependencies for your website, while deploying the site you need to check for dependiences (i.e.) dll files which are necessary for running your application,
in the app_code folder you got the dll, so while deploying the site your deployment should contain the dll file also.

for the error you are getting please refer the link below.
Compiler Error CS0246
please refer the below links for hosting webservice in ii7.
Publishing a Web Service on IIS 7 Server
Deploying ASP.NET Websites on IIS 7.0
hope this helps.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now