Link to home
Start Free TrialLog in
Avatar of quest_capital
quest_capital

asked on

C# Web Services Compilation Error

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

Avatar of Cong Minh Vo
Cong Minh Vo
Flag of Viet Nam image

how define BL class?
Avatar of quest_capital
quest_capital

ASKER

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

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
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.
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?
I deployed the web site an I got the dll for the App_Code folder but I still get the same error.
ASKER CERTIFIED SOLUTION
Avatar of jitendra patil
jitendra patil
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial