I have the following Wcf Data Service:
public class WcfDataService : DataService<WcfDataServiceContext> { public static void InitializeService(DataServiceConfiguration config) { config.SetEntitySetAccessRule("*", EntitySetRights.All); config.SetServiceOperationAccessRule("*", ServiceOperationRights.All); config.UseVerboseErrors = true; } [WebGet] public IQueryable<Person> GetPeopleByName(string name) { WcfDataServiceContext context = this.CurrentDataSource; var match = from p in context.People where p.FirstName == name select p; return match; }
I can access the custom method from the browser like this:
http://127.0.0.1:8080/DataService/WcfDataService.svc/GetPeopleByName?name='Daniel'
How can I call that method and get that list of Person from a Silverlight application?
I'm using Visual Studio 2012, Silverlight 5, .NET Framework 4.0.
Answer: 1
As far as I remember whe using Silverlight you cannot connect to a different server than the one the Silverlight app came from so you would just use a relative Uri. If you would like to use WCF Data Services client you can take a look here: http://forums.silverlight.net/t/208481.aspx - there is a code snippet that shows it. However AFAIK WCF Data Services client does not support Service Operation so you may need to use XmlReader to be able to query and parse the response of the GetPeopleByName function.
by : Pawelhttp://stackoverflow.com/users/1168070Answer: 2
I did it before I can share.Service Reference your domain:8080/DataService/WcfDataService.svc then For Person object use [DataContract] attribute for properties of Peson use [global::System.Runtime.Serialization.DataMemberAttribute()] By this way you say Serialize and create proxies to Bus side. Notice this attributes because it really works!
//Here is the interface attributes are important namespace AHBSBus.Web.Services { [ServiceContract] public interface IChatService { [OperationContract] bool LogIn(Guid userID,Guid roomID); [OperationContract] bool LogOut(Guid userID,Guid roomID); [OperationContract] IEnumerable<VW_CHATUSERDETAIL> GetLatestMessages(Guid userID,Guid roomID,Guid lastSyncMessageID); [OperationContract] bool SendMessage(Guid fromID, Guid roomID, Guid toID, string message); [OperationContract] IEnumerable<ChatUser> GetLoggedInUsers(Guid roomID); [OperationContract] bool IsLogin(Guid roomID,Guid userID); } } //Implementation of service [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] public partial class ChatService:IChatService { //Here goes }
by : Davut Gürbüzhttp://stackoverflow.com/users/413032
No comments:
Post a Comment
Send us your comment related to the topic mentioned on the blog