This code is written in wcf Service1.svc.cs
using System;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.ServiceModel.Activation;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Web.Script.Serialization;
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class enggcollegelist : ICRUD
{
public List<string> autobranches(string brname)
{ List<string> lstbranches = new List<string>();
connection = new SqlConnection(ConnectionString);
command = new SqlCommand("select branchname from tblenggbranchnames "+"where branchname LIKE '%'+#branches+'%' ",connection);
connection.Open();
command.Parameters.AddWithValue("#branches",brname);
resultReader = command.ExecuteReader();
while (resultReader.Read())
{
string items =AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(resultReader["branchname"].ToString());
lstbranches.Add(resultReader["branchname"].ToString());
}
connection.Close();
return lstbranches;
}
In above code "AjaxControlToolkit" is not accepting.
I have downloaded ajax toolkit and installed and also add reference in toolkit.
But same problem exits.
Related
Below is the sample I found from online Tutorial to host the website suing OWIN, however when I try to run on my machine, I got this error
CS0246 The type or namespace name 'Func<,>' could not be found (are you missing a using directive or an assembly reference?)
I think for using 'Func<,>' I have using System, and for IDictionary, I have using System.Collections.Generic; so I don't understand why it still can't work.
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
using AppFunc = Func<IDictionary<string, object>, Task>;
public class Startup
{
public void Configuration(IAppBuilder app)
{
var middleware = new Func<AppFunc, AppFunc>(MyMiddleWare);
app.Use(middleware);
app.Use<OtherMiddleware>();
}
public AppFunc MyMiddleWare(AppFunc next)
{
AppFunc appFunc = async (IDictionary<string, object> environment) =>
{
var response = environment["owin.ResponseBody"] as Stream;
byte[] str = Encoding.UTF8.GetBytes("My First Middleware");
await response.WriteAsync(str, 0, str.Length);
await next.Invoke(environment);
};
return appFunc;
}
public class OtherMiddleware : OwinMiddleware
{
public OtherMiddleware(OwinMiddleware next) : base(next) { }
public override async Task Invoke(IOwinContext context)
{
byte[] str = Encoding.UTF8.GetBytes(" Other middleware");
context.Response.Body.Write(str, 0, str.Length);
await this.Next.Invoke(context);
}
}
}
You need to put the AppFunc in the class so it can use the using,
Or you can use full namespace for Func, IDictionary and Task
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Owin;
using Owin;
// Use this
using AppFunc = System.Func<System.Collections.Generic.IDictionary<string, object>, System.Threading.Tasks.Task>;
public class Startup
{
// Or this
using AppFunc = Func<IDictionary<string, object>, Task>;
...
}
For me it was low .NET Target Framework version 2.0 of application. Changed to 4.7 (it seems minimal is 3.5).
You need to make sure you added the reference System.Runtime.CompileServices to your project as you see in here: https://msdn.microsoft.com/en-us/library/bb549151(v=vs.110).aspx the delegate is part of mscorlib assembly.
I am following a code sample in this link.
I hit a snag right on the second line:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using EnvDTE;
namespace TwinCAT_Automation_Interface
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
//Creating TwinCAT Projects via templates (Recommended)
Type myType = System.Type .GetTypeFromProgID ("VisualStudio.DTE.12.0");
dynamic myDTE = System.Activator.CreateInstance (myType); //error right here
}
}
The error says:
Error 1 A field initializer cannot reference the non-static field,
method, or property 'TwinCAT_Automation_Interface.Main.myType'
What exactly am I doing wrong? It's the same code snippet; I just modify it a bit. Please help!!!!
OK, I got it fixed by changing it to the following:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
//using EnvDTE;
namespace TwinCAT_Automation_Interface
{
public partial class Main : Form
{
public Main()
{
InitializeComponent();
}
public void myMethod()
{
//Creating TwinCAT Projects via templates (Recommended)
Type myType = System.Type .GetTypeFromProgID ("VisualStudio.DTE.12.0");
dynamic myDTE = System.Activator.CreateInstance (myType); // dynamic linking for DTE-object
}
}
}
The explanation is in this link. It is a compiler error.
It is a compiler error. See question for link to the answer.
I'm trying to make a simple project in ASP.NET, 'code first'.
So I made a class EFDbContext:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
namespace MVCRubenWouters.Models
{
public class EFDbContext: DbContext
{
public EFDbContext() : base("name=rubenwoutersdbCF")
{
Database.SetInitializer<EFDbContext>(new EFDbInitializer());
}
public DbSet<Types> Types { get; set; }
}
}
And added a connectionstring in 'web.config'
<connectionStrings>
<add name="rubenwoutersdbCF" connectionString="Data Source=.\SQLSERVER2012;Initial Catalog=rubenwoutersdbCF;Integrated Security=True;MultipleActiveResultSets=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
Then I created a class "EFDbInitializer to add something to the database:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
namespace MVCRubenWouters.Models
{
public class EFDbInitializer: DropCreateDatabaseAlways<EFDbContext>
{
protected override void Seed(EFDbContext context)
{
Types t1 = new Types()
{
PK_TypeNr = 1,
TypeKeuken = "Belgisch",
TypeZaak = "Restaurant",
Vegetarisch = false
};
context.Types.Add(t1);
context.SaveChanges();
}
}
}
When I run the project and go to the SQL server management studio (and refresh), no new database is there..
Am I doing something wrong here? :/
I would suggest you create your database in SQL server, build your tables, then fill them using your code.
The way that runs on my system is force the database in Application_Start()
try this:
Database.SetInitializer(new CreateDatabaseIfNotExists<EFDbContext>());
var context = new EFDbContext("Data Source=(local);Integrated Security=SSPI;Initial Catalog=myDB;");
context.Database.Initialize(true);
I think the seed method is never called, To ensure set a brakpoint
You can develop your custom intializer something like below link:
Seed in entity framework and then call it in Application_Start()
Database.SetInitializer<EFDbContext>(new EFDbInitializer());
hi i have the following code:
but i m getting an error
'newwcf.Client' does not contain a definition for 'Where'
please help..
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Data;
namespace newwcf
{
public class myservice : Imyservice
{
public List<ClientDetails> getClient()
{
List<ClientDetails> client = new List<ClientDetails>();
var sql = Client.Where(cn => cn.ClientName).ToList(); //getting the error here
return sql;
}
}
}
c# is case sensitive...should you try
var sql = client.Where(cn => cn.ClientName).ToList();
I have my controller decorated with: [BasicAuthentication] - however, putting in breakpoints, and stepping through the code, the [BasicAuthentication] never redirects to the Auth.cs (in the Filter folder):
Filter\Auth.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Threading;
using System.Web;
using System.Web.Security;
namespace ebapi.Filter
{
public class BasicAuthenticationAttribute : System.Web.Http.Filters.ActionFilterAttribute
{
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
So the override OnActionExecuting never executes - but I cannot see what I've missed. My controller, decorated with [BasicAuthentication] is shown below, but doesn't invoke my Auth.cs shown above:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity.Infrastructure;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using ebapi.Filter;
using ebapi.Models;
namespace ebapi.Controllers
{
public class GetBookingsController : ApiController
{
private GetBookingsContext db = new GetBookingsContext();
private ApiMembersContext dba = new ApiMembersContext();
// GET api/GetBookings/5
[BasicAuthentication]
public IEnumerable<GetBooking> GetBooking(long id)
{
Thanks for any help,
Mark
if this helps, I changed the
public class BasicAuthenticationAttribute name to: public class BasicAuthenticationV2Attribute
and changed the decoration to:
[BasicAuthenticationV2]
For whatever reason, this started the authentication again, and it fired with no problem.
I'm assuming there is some sort of caching going on, perhaps from the calling IP to the API - that means it remembers it's already authenticated someone, and doesn't need to again?
If anyone could confirm my thinking, I'd appreciate it.
Thank you,
Mark