Solved

C# Web Services Compilation Error

Posted on 2014-04-04
7
420 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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