0

Hi I am just learning WCF and am trying to create an web service for an existing ASP.NET MVC 4 applicatation.This is what I have done so far:

I have created a WCF Service Application. I defined the data contract and the data members:

[DataContract]
public class BookData
{
    [DataMember]
    public int Id { get; set; }

    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public string Author { get; set; }

    [DataMember]
    public string Description { get; set; }

    [DataMember]
    public DateTime PublicationDate { get; set; }

    [DataMember]
    public int CategoryId { get; set; }

    [DataMember]
    public decimal Price { get; set; }

    [DataMember]
    public string BookUrl { get; set; }
}

I have defined the service contract:

[ServiceContract]
public interface IBookService
{
    IEnumerable<BookData> GetBooks(int pageNumber, int numberOfBooksOnPage);
    IEnumerable<BookData> GetBookByCategory(int categoryId, int pageNumber, int numberOfBooksOnPage);
    BookModel GetBookById(int bookId);
    int CountBooks();
    int CountBooksByCategory(int categoryId);
    void AddBook(BookData book);
    void UpdateBook(BookData book);
    void DeleteBook(int bookId);
}

There was an existing Service1.svc file witch I renamed to BookService.svc. When double clicking this file it is actually a class and I made it inherit from IBookService and implemented all the methods.

When I right click on the BookService.svc and click view in Browser I get this error:

The type 'BookService.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.

How can I solve this problem?

Jeff B
  • 8,572
  • 17
  • 61
  • 140
aleczandru
  • 5,319
  • 15
  • 62
  • 112

1 Answers1

11

Answering an old question just for the benefit of all google searchers :) I just had the same problem.

While trying to solve it, I found out I forgot to change the class name in the markup section of my "file.svc".

Right click your "file.svc" and choose "view markup"

There you will find a very long line with a part like: Service="SomeRootNameSpace.class1" You should change 'class1' to the real class name.

Please let me know if it helped or if you already solved it. If the above is not clear tell me and I will try to re-explain.

elixenide
  • 44,308
  • 16
  • 74
  • 100
Guy Cohen
  • 689
  • 1
  • 9
  • 25