Solved

C# Web Services Compilation Error

Posted on 2014-04-04
7
395 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

15 Experts available now in Live!

Get 1:1 Help Now