I am wprking on a project and I have 2 projects in one solution. I added my WCF project and inside it I added an entity framework. Also in Service1.svc I can reach the classes and use them for saving like
public bool saveuser(User user)
{
}
For example User is the name of my database and Its pretty fine working in WCF part but at WPF part Im trying to access this class again to fill this class's object and I using MyClass.ServiceReference1; on the top and Inside one of my method I can not reach this class. What should be the solution why I can not access my class instead I added this WCF service as a service reference and enabled async operations.
Im newbie and thanks
Sincerely
Related
I have been assigned the task of removing the WCF aspects of the solution and tp plug the GUI directly into Entity Framework objects. Currently the WCF service lives between the GUI (WPF) and any entity framework aspects.
I apologize for not being more knowledgeable about what I am asking about but I am brand new to these technologies. I am hoping that something "jumps right off the page" for some to give me answers about.
I am actively in the process of learning about these things and I have the application in a .sln file so I can dissect it in Visual Studio. Thanks in advance for any help.
The GUI needs to have controls bound to the data without using WCF, thanks
According to your question, I assume you have two class libraries for WCF services, entity framework and a WPF application.
What you can do is create a mock class inside the WPF application and Entity framework class library to link both entity framework and WPF application.
The First step, implement methods inside the class of WPF application to call Entity framework class methods.
The Second step, implement methods inside Entity Framework mock class to communicate with entities and tables to retrieve values from the database through ADO Model.
Example :
WPF Application Mock Class
public class DBWrapper
{
public bool AddCandidate(Candidate mCandidate)
{
DBAccess dba=new DBAccess();
dba.AddCandidate(mCandidate);
}
}
Entity Framework Class Library Mock Class
public class DBAccess
{
public bool AddCandidate(Candidate mCandidate)
{
try
{
//Entity framework entities object instantiation
var hrEntities=new HREntities();
hrEntities.Candidate.Add(mCandidate);
hrEntities.SaveChanges();
return true;
}
catch(Exception ex)
{
return false;
}
return false;
}
}
Hope this helps you.
I have a solution with this structure :
ProjectName.Domain ==> contains POCO classes (EntityFramework
code first classes) ProjectName.DataAccess ==> contains DbContext
and EntityFramework mapping codes. ProjectName.Task ==> It's my
bushiness layer . ProjectName.Presnetation.MvcClient ==> It's
ASP.NET MVC web client.
ProjectName.Presentation.SilverlightClient ==> It's Silverlight 5
client. ProjectName.WCFRiaClassLibrary ==> It's layer between
business logic and Silverlight client
I've decided to handle logic such as queries and CRUD operations in business logic and use ProjectName.Task in domain service class.
I can't find any sample that use EF code first approach and load entities from another project , can you please help or give me link ? because when I try to create my DomainService class without wizard I can't find generated proxy classes in silverlight client project .
I'm doing something like this :
[EnableClientAccess()]
public class CrudService : DomainService
{
private readonly IEntityTask _entityTask;
public CrudService(IEntityTask entityTask)
{
_entityTask = entityTask;
}
public IQueryable<Entity> GetAll ()
{
return _entityTask.GetAll().AsQueryable();
}
}
Is this possible to use code first classes from another project with WCF Ria Service ?
What is wrong with my approach?
Defintely possible. Take a look at this question to see possible problems with wcf ria + ef
EDIT:
I've just written a small blog post attaching to it a functional project. You can find it here
I have created a class so that I can bind it to a combo box. I have a solution where there are two projects test and test.web. In the test.web I have added a new class so that I can bind it to a combobox. In the same test.web I have created few entities with help of ADO.net Entity Object Generator and those classes can be seen when I am trying to add my class as resource to a grid. Why not my class?
When I add my class as resource I get error the type '..' was not found. Verify that you are not missing assembly reference....
Finally I found the answer. My understanding of SilverLight was wrong as I am still learning it. I found out that I cannot directly access all the class in the model on the client side directly. They all should be exposed using DomainService and DomainService is the thing which you can access on the client side, if you have to access your class expose that through DomainService.
I was using a simple WCF service with silverlight but I wanted to validate data with annotations and I didn't want to write a whole new layer in silverlight project. So I decided to switch to using a DomainService, created through generating code in the silverlight project.
Now comes the trouble. I have a parent class and about 10 derived classes. Through WCF, I was able to just use the base class. Now I am trying to use a DomainService with the base class decorated with the KnownType attribute. The problem is now those attributes get replicated in silverlight client and a compilation error is thrown. Anybody know how to use DomainService with inheritance? I want to deliver only the information from the base class.
I don't completely follow what your problem is, but this is a great tutorial on how to use Domain Services in Silverlight, and the example includes an abstract base class for all entities, similar to what I think you're doing.
I have the following Ria Service define:
namespace SilverlightTest.Web
{
[EnableClientAccess()]
public class ContactService : LinqToEntitiesDomainService<AdventureWorksEntities>
{
public IQueryable<Contact> GetContactSearch(string lastName)
{
ContactRepository rep = new ContactRepository();
return rep.SearchByLastName(lastName);
}
}
}
When I compile the solution, my SilverlightTest project does create the SilverlightTest.Web.g.cs file and the appropriate Context objects are created when I look at it. However, when I attempt to import the SilverlightTest.Web namespace to access the Data Context class for the above service, it says it cannot find the Web namespace.
The only difference I can see between what I'm doing and many examples that are out there on the web is that my AdventureWorksEntities data context is located in a separate business object dll. I tried to query the context directly instead of using the Repository Pattern I'm attempting to do and it also isn't work working.
Any ideas? Is it possible to have Ria Services access a separate DLL handling data access or does it HAVE to be in the same project?
I've been able to put the Ria service in a separate project before, although I do remember having issues. Not sure exactly what it was, but I would check two things: your references and your web.config (in the hosting website). When you add a ria service to a web project it does some things behind the scenes that wire everything up correctly.
Could try adding a service to your web project temporarily and see what it adds.
It seems that Resharper does not recognize the .gs files and their name spaces. If you disable R# or just code without intelisense it works.