Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

C# Web Services Compilation Error

Posted on 2014-04-04
7
Medium Priority
?
459 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 13

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 13

Accepted Solution

by:
Jitendra Patil earned 1500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

636 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