Ria Service Generated Code Not Accessible in Silverlight Code - silverlight

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.

Related

What is the alternate way for "Request" class/object in .NET core?

I am migrating an existing ASP.NET Web API 2 project to ASP.NET Core. While migrating I am unable to find this.Request object. Can anyone help me solve out this issue?
This question was asked here, but since ASP.NET Core was still probably in an RC state then, I figured I'd answer here instead of referring to there because there is some stuff that's obsolete or completely gone from the official release.
Assuming your controller class inherits from Controller (or more specifically, ControllerBase) then it does have a this.Request property as you can see here and here. As Pawel noted, you can also access it from the this.HttpContext property.
The request's URL is broken up into several properties on HttpRequest. You can access the URL in a friendlier API by adding using Microsoft.AspNetCore.Http.Extensions; which gets you access to the following extension methods:
GetDisplayUrl()
GetEncodedUrl()
As far as the query string, HttpRequest provides QueryString and Query properties for you to interact with.
Side note: I just created an app from scratch targeting ASP.NET Core on .NET Core for the first time on this laptop, and it took a while for the Intellisense to work for the Request property, so I'm wondering if that could have been your issue.
You need to override your class like this to get this.Request
public partial class _Default : System.Web.UI.Page

Entity Namespace does not appear in Silverlight project

I have a Silverlight web project where I apply the MVVM pattern. In my entire solution I have 4 projects.
Project "A3", which contains all of my Views and ViewModels.
Project "A3.Web", which contains my main html files, images, sound files, etc.
Project "A3Lib", which contains my XAML binding converters and other helpful classes that I created.
Project "A3Lib.Web", which contains the Data Models and Domain Logic.
All of my entity models are inside my DataModels folder and all of my Domain Service server side code is inside the DomainLogic folder. I created a new folder inside the DataModels folder named "Common".
So when I want to add the data model to my VM, I tried "using A3Lib.Web.DataModels.Common;" and that did not find the namespace.
Issue: when I add a new folder and a new entity model to the DataModels folder, I do not see the namespace in my View or ViewModel in the "A3" project.
However, I already have existing code there (was added by someone else) and the models he added show perfectly fine (when doing using ...... in the View or VM).
I checked web.config to make sure the connection string is there and it's correct. I also tried to add a brand new context to the base class of the project (where other contexts are) and that did not help. My project simply cannot resolve or see the data model namespace that I create.
Thanks
Yura
The Silverlight app sees the models and namespaces from the server-side project through the generated code - you should see it in the Generated_Code folder of your A3Lib project. If it is not there, then the proxy classes are not being generated on build. A couple things to check:
class is not private (hey - sometimes it's the simple things)
if using Domain Services, the service needs to have at least 1 method that returns an IQueryable or IEnumerable (even if method returns null) in order to see the class in the Silverlight-side domaincontext
if the class is just a utility class that you want to share with the client, save the file as classname.shared.cs, and the proxy will pick it up.
make sure the project references are to the projects and not (possibly older) .dlls in another location.
That's all I've got based on the info provided.

WPF WCF Entity Framework Can not view Classes in WPF project

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

RIA Services library and resource strings in meta attributes

I've split out my domain services into a separate WCF RIA Services Class Library project. However there now seems to be a problem with using the resource strings in the client side library.
e.g.
The client project library has generated code like this:
[DataMember()]
[Display(Description="FullNameDescription", Name="FullNameLabel", Order=-1, ResourceType=typeof(MetadataStrings))]
[StringLength(255, ErrorMessageResourceName="BadFullNameLength", ErrorMessageResourceType=typeof(MetadataStrings))]
public string FullName
{
// ...
}
where MetadataStrings is a resource file in the class library. This class library is then referenced by the silverlight project.
But the meta attributes that use ResourceType cause the designer to throw an exception when opening a view and at runtime cause a MissingManifestResourceException.
If I comment out the attributes and rebuild it all works fine. So something is not right with the resources being in another assembly i'm guessing?
Edit: Nevermind finally got this working, problem was that i renamed my class library projects and the namespace of the resource file was wrong. 3 days wasted.

Sending abstract class with DomainService WCF service to Silverlight

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.

Resources