.NET Diary

November 20, 2009

Error: The type ‘YourType, YourAssembly’, provided as the Service attribute value in the ServiceHost directive could not be found – Problem while using WCF

Filed under: All, ASP.NET — leoullas @ 4:13 am

Error lied in ServiceIHaveMade.svc file. Need to implement the name change from ‘Service1’ to ‘ServiceIHaveMade’ here too along with the web.config file.

Before:
<%@ ServiceHost Language="C#" Debug="true" Service="WcfService_Learn.Service1" CodeBehind="ServiceIHaveMade.svc.cs" %>
After:
<%@ ServiceHost Language="C#" Debug="true" Service="WcfService_Learn.ServiceIHaveMade" CodeBehind="ServiceIHaveMade.svc.cs" %>
 

Web.config(partial)

<system.serviceModel>

       <services>

              <service name="WcfService_Learn.ServiceIHaveMade" behaviorConfiguration="WcfService_Learn.ServiceIHaveMadeBehavior">

              <!-- Service Endpoints -->

              <endpoint address="" binding="wsHttpBinding" contract="WcfService_Learn.IService1">

              <!-- Upon deployment, the following identity element should be removed or replaced to reflect the identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity automatically. -->

                     <identity>

                           <dns value="localhost"/>

                     </identity>

              </endpoint>

              <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

              </service>

       </services>

       <behaviors>

              <serviceBehaviors>

              <behavior name="WcfService_Learn.ServiceIHaveMadeBehavior">

              <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->

                     <serviceMetadata httpGetEnabled="true"/>

                     <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->

                     <serviceDebug includeExceptionDetailInFaults="false"/>

              </behavior>

              </serviceBehaviors>

       </behaviors>

</system.serviceModel>
Advertisements

November 3, 2009

Generics

Filed under: All, ASP.NET, C# — leoullas @ 8:55 am

Generics are a new feature in version 2.0 of the C# language and the common language runtime (CLR). Generics introduce to the .NET Framework the concept of type parameters, which make it possible to design classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code. For example, by using a generic type parameter T you can write a single class that other client code can use without incurring the cost or risk of runtime casts or boxing operations, as shown here:

C#

// Declare the generic class
public class GenericList<T>
{
    void Add(T input) { }
}
class TestGenericList
{
    private class ExampleClass { }
    static void Main()
    {
        // Declare a list of type int
        GenericList<int> list1 = new GenericList<int>();

        // Declare a list of type string
        GenericList<string> list2 = new GenericList<string>();

        // Declare a list of type ExampleClass
        GenericList<ExampleClass> list3 = new GenericList<ExampleClass>();
    }
}
  • Use generic types to maximize code reuse, type safety, and performance.
  • The most common use of generics is to create collection classes.
  • The .NET Framework class library contains several new generic collection classes in the System.Collections.Generic namespace. These should be used whenever possible in place of classes such as ArrayList in the System.Collections namespace.
  • You can create your own generic interfaces, classes, methods, events and delegates.
  • Generic classes may be constrained to enable access to methods on particular data types.
  • Information on the types used in a generic data type may be obtained at run-time by means of reflection.

//For Interfaces
interface IComparable <T>
//for structs
struct HashBucket <K,D>
//for methods
static void Reverse <T> (T[] arr)
//for delegates
delegate void Action <T> (T arg)

Strongly TYPED & Loosely TYPED

Filed under: All, ASP.NET, C# — leoullas @ 8:49 am

Definition: A strongly typed programming languages is one that requires the type of a variable to be explicitly stated. C is a strongly typed language. You must declare the type of data a variable will store for C to interpret it:

int myVariable;
myVariable = 25;

Perl is a loosely typed language. There is no need to declare the variable type before using it:

$myVariable = 25;
$myVariable = “A String.”;

Basic dode to fetch data from sql server using select statement and put it in dataset using dataadapter

Filed under: All, ASP.NET, C# — leoullas @ 8:42 am

System.Data.SqlClient.SqlConnection objConnection;

System.Data.DataSet objDataSet = new DataSet();

System.Data.SqlClient.SqlDataAdapter objDataAdapter;

objConnection = new SqlConnection("data source=192.168.93.60; uid= tallyman; pwd= tallyman; database=Tallyman");

#region Either of these 2 works

//objDataAdapter = new SqlDataAdapter("Select top 5 id from accounts", "data source=192.168.93.60; uid= tallyman; pwd= tallyman; database=Tallyman");

objDataAdapter = new SqlDataAdapter("Select top 5 id from accounts", objConnection);

#endregion Either of these 2 works

objDataAdapter.Fill(objDataSet, "accountsData");

Console.Write(objDataSet.Tables["accountsData"].Rows.Count);

Console.Read();

Create a free website or blog at WordPress.com.

%d bloggers like this: