2

I am following this tutorial to create dynamic search results from an SQL server as a user types. It is telling me to create a .asmx file, which is not a format I have ever worked with before. I now have a .asmx and .asmx.cs file. Here is the code I have thus far :

WebService.asmx.cs :

public class SearchService : WebService
{
  [WebMethod]
  public searchResult[] Search(string txtSearch)
  {
//Declare collection of searchResult
        List resultList = new List();
        var db = Database.Open("mPlan");
        var result = db.Query("SELECT * from Users where Username like '%" + txtSearch + "%'");
       try
       {
           foreach(var record in result)
            {
               searchResult result = new searchResult();
               result.Username = ["Username"].ToString();
               resultList.Add(result);
           }
           return resultList.ToArray();
       }
       catch
       {
           return null;
       }
  }}

WebService.asmx :

<%@ WebService Language="C#" class="WebService" %>
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;

[System.Web.Script.Services.ScriptService]
[System.Web.Script.Services.GenerateScriptType(typeof(searchResult))]
public class searchResult
{
    public string Title;
    public string img;
    public string href;
}

Here is my error message, can anyone help me with this please?

Parser Error Message: Could not create type 'WebService.asmx.cs'

It highlights line 1 of WebService.asmx as the source of the error.

3
  • class="WebService.asmx.cs" should probably be class="SearchService" Commented Mar 12, 2012 at 15:59
  • Why did you edit your posted code? Your question now makes no sense. Commented Mar 12, 2012 at 16:04
  • @JohnSaunders Reverted back,I did not think of that! :) Commented Mar 12, 2012 at 16:10

3 Answers 3

5

I've come across this error using Visual Studio Development Server when my project output directory was not bin\

One of my DLLs has versions for different platforms (x86, x64), so I created corresponding configurations, and they got by default output directories like this: "bin\x86\Dedug", "bin\x64\Debug". But the Visual Studio Development Server still tried to load binaries from the bin\ folder and of course failed.

I fixed the issue by specifying bin\ output folder in my debug configurations.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks!! I just fought this (in my WebServiceHost project) for an embarrassingly long time : ).
Had the same problem... output was set to /x86/bin. Changing to /bin fixed it right up.
4

class="..." expects a fully-qualified class-name, not a filename.

Comments

2

The correct class name is "SearchService". You specified a file name.

8 Comments

Thank you for this, I have now edited my code above. I am still, however, getting the error Could not create type 'SearchService'.
Because it needs the fully-qualified name of the type.
Also, are you using a web site "project"? Bad idea. Use a web application project.
I believe the fully qualified name is SearchService? I have tried Folder.SearchService and this returns the same error. Apologies for the stupid questions, I am very new to this language.
Again, is this a web site "project"? It would have been created by File->New Web Site instead of File->New Project. It has implications on what the fully-qualified name is.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.