Quantcast
Channel: WCF Data Services forum
Viewing all 877 articles
Browse latest View live

deserialization/serialization hooks in 5.4

$
0
0
The atom payload is massive, so we need to move to JSON. However, there is a problem with the WCF Data services server, where it falls over when a property is included in the payload that it doesn't expect... So, we have to resort to using the WritingEntity event handler (Google: Customizing Serialization of Entities in the ADO.NET Data Services Client Library)


However, this only works with atom.


In the 5.4 release blog post it said there are new deserialization/serialization hooks, what are they, can they be used with JSON?

Spatial Data Type Mismatch between Entity Framework and WCF Data Services

$
0
0

The mismatch of the Spatial Data Types between Entity Framework and WCF Data Services has been discussed before, but there is no indication, when this (stupid) mismatch will be fixed.

The expectations are pretty simple: I have a database table with an attribute of type Geometry. Using the Entity Framework (in VS2012 professional) I prepare a data model for a WCF Data Service to be published/edited in OData. What work in a few minutes with all base types does not work with spatial data types.

It seems that two developer teams at Microsoft developed the same library twice, once for WCF and once for Entity Framework, but the two do not match. Can someone at Microsoft tell me, when a solution can be expected (either one library thrown away or both adjusted to each other...)?

Thanks!

Entity Framework 6 support or open source EF provider?

$
0
0

Is there a plan to add support for the upcoming Entity Framework 6 or maybe an open source implementation of the for EF6 provider? Currently when running the service that was created from the simple context we are getting the error:

The exception message is 'Expression of type 'System.Data.Entity.Core.Objects.ObjectContext' cannot be used for return type 'System.Data.Objects.ObjectContext''

The issue is obviously that WCF library references System.Data.Objects.ObjectContext inside System.Data.Services.Provides.CreateDbContextAccessor method which causes the incompatibility since EF6 usesSystem.Data.Entity.Core.Objects.ObjectContext. What are my choices now, do I have to wait for the next WCF library release or write my own WCF EF Provider or is there a better and quicker option?

Did anyone try creating wcf odata service from EF context?

Here is the simple service implementation:

 

    public class WcfDataService1 : DataService
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
            // Examples:
            // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
            // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        }
    }

    public class TestContext : DbContext
    {
    }
and a review.svc looks like this:


<%@ ServiceHost Language="C#" Factory="System.Data.Services.DataServiceHostFactory, Microsoft.Data.Services, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" Service="WcfDataService1" %>

 

 


create object of viewModel in view in asp.net mvc

$
0
0

I create an object of class in controller in asp.net mvc and pass it to view page  by view model ,

This object has many methods  that return different data type( xmldocument , string, int , array, … etc)

I use the following way to access any methods

"@Model.Getxml().ChildNodes.Count"

"@Model.Getxml().ChildNodes[0].InnerText"

I want to declare a variable of this object in javascript and call any methods that I want from the variable like the following

var obj=@Model

And then access any methods from obj variable

because I have a problem when write for loop for tracing elements in array like the following

var size=parseInt("@Model.Getxml().ChildNodes.Count");

     for  (var i=0; i<size; i++)

    {

        document.writeln ("@Model.Getxml().ChildNodes[i].InnerText");

}

This code didn't work

can you help me please 



OData Provider Toolkit?

$
0
0

I've found dozens of posts online noting that this toolkit is a great resource for samples and how-tos

The link is 'supposed' to be http://www.odata.org/ecosystem/#samplecode but when I navigate to that page under 'Sample Code' all the links are broken and there is no way to download the toolkit. Can someone at MSDN provide a mirror until this is fixed so I can download the code? 

thanks

Data Services Client fails to identify keys named Id

$
0
0

I'm using the WCF Data Services client with a portable model library shared between the server and client - ie I'm not using a generated client with proxy classes.

Things work as expected, with the glaring exception that the WCF Data Services Client library does not work with keys named Id or (ClassName)Id.  The client requires keys to be named "ID", otherwise a class is not identified as an entity class.

This is broken for several reasons - one, all the other ADO.NET libraries (EF) etc. allow the "Id" naming convention (and they also allow "ID", but don't require it).  In much of the .NET framework, "Id" is used.   Second, which types are entities are spelled out in the $metadata document/EDM model; but the client disqualifies the type anyway if it doesn't like the key name.

Using ReSharper disassembly, I was able to examine the client code and saw that the string.EndsWith("ID") is hard-coded.

I can't/don't want to use the attributes, b/c our model library is portable and is independent of web service/remoting concerns.

To use the WCF Data Services client, we had to rename all our keys to "ID".

errors when access sql server using WCF

$
0
0

I got this error when using WCF to access SQL server. I attached the code. Basically, I created console application as WCF server side, and use datagridview on a winform to view the data. I did run the server side before the winform. Please help me thanks

class Program
    {
        [ServiceContract]
        public interface IService
        {
            [OperationContract]
            string TestMethod();
            [OperationContract]
            DataTable GetDataByTable();
        }

        public class MyService : IService
        {
            public string TestMethod()
            {
                 string a = "aaaaaaa";
                 return a;
            }

            public DataTable GetDataByTable()
            {
                DataSet ds = new DataSet();
                DataTable table = null;
                SqlConnection connection = new SqlConnection
                ("Data Source = .; Inital Catalog =dnt31; Integrated Security = true");
                connection.Open();
                try
                {
                    SqlDataAdapter sda = new SqlDataAdapter("select * from [dbo].[dnt_users]", connection);
                    sda.Fill(ds, "[dbo].[dnt_users]");
                    if (ds != null && ds.Tables.Count > 0)
                    {
                        table = ds.Tables[0];
                    }
                }
                catch (Exception e)
                {
                }
                finally
                {
                    connection.Close();
                }
                return table;
            }
        }

        
        static void Main(string[] args)
        {
            Uri baseURI = new Uri("http://localhost:8008/Service");
            using (ServiceHost host = new ServiceHost(typeof(MyService), baseURI))
            {
                WSHttpBinding binding = new WSHttpBinding();
                binding.Security.Mode = SecurityMode.None;
                host.AddServiceEndpoint(typeof(IService), binding, "my");
                ServiceMetadataBehavior mdBehavior = new ServiceMetadataBehavior()
                {
                    HttpGetEnabled = true

                };
                host.Description.Behaviors.Add(mdBehavior);
                host.Opened += (sender, e) => Console.WriteLine("Service Started");
                try
                {
                    host.Open();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
                Console.ReadKey();
                host.Close();
            }
        }
    }

 public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (WS.ServiceClient proxy = new WS.ServiceClient())
            {
                DataTable dt = proxy.GetDataByTable();
                if (dt != null)
                {
                    dataGridView1.DataSource = dt;
                }
            }
        }


How to Add OData Service

$
0
0

 I first tried to follow the instructions in the book "Programming Microsoft SQL Services 2012" page 512 and when that did not work, I tried following the instructions athttp://msdn.microsoft.com/en-us/library/vstudio/cc668184.aspx

I'm using SQLExpress 2012 and Visual Studio 2012 Update 2 on Windows 8.

Now the book "Programming Microsoft SQL Services 2012" says to add a new WCF Data Service to an existing ASP.NET project (same as MSDN directions) with visual studio and fill in the C# code template. Fine.

using System;
using System.Collections.Generic;
using System.Data.Services;
using System.Data.Services.Common;
using System.Linq;
using System.ServiceModel.Web;
using System.Web;

namespace HelloMvc4WebApp
{
    public class PropertyGoalSetterODataService : DataService< Project1Context >
    {
        // This method is called only once to initialize service-wide policies.
        public static void InitializeService(DataServiceConfiguration config)
        {
            // TODO: set rules to indicate which entity sets and service operations are visible, updatable, etc.
            // Examples:
            // config.SetEntitySetAccessRule("MyEntityset", EntitySetRights.AllRead);
            // config.SetServiceOperationAccessRule("MyServiceOperation", ServiceOperationRights.All);
            config.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
            config.DataServiceBehavior.MaxProtocolVersion = DataServiceProtocolVersion.V3;
        }
    }
}

And then in the solutions explorer the book says I'm supposed to right click on the newly created ".svc" file and select "view in browser". Hmmm... strange. Don't I need to start the Web App first? (But if I start the web app first, then the menu entry for "view in browser" disappears for the .svc file). Hmmm. really strange...

(1) This "show in browser" does not work for me. I get "Server Error in '/' Application'.. HTTP 404... What is wrong? Is this a bug in Visual Studio? Incidentally, I followed the directions to turn off "feed reading view" in IE 10.

Now it looks like, from the Add Service Reference Dialog box discover button, that I am supposed to create the client in a child project because the discover button will look in the same project. Is this strange? Normally you have to have the server running to query the meta-data -- correct? But you cannot add a service reference if the parent ASP.NET project is running!

So I tried it without the ASP.NET Web App running by clicking on the discover button (which fills in "http://localhost:56727/PropertyGoalSetterODataService.svc") and I click OK and it says "there was an error downloading the metadata from the address. Please verify that you have entered a valid address! Well I did not enter the address, Visual Studio did! Therefore I did not mistype it! So why does visual studio think it can download the meta data if the service is not running?

(2) Is this really supposed to work? What am I doing wrong?

So I give up on this approach and start the ASP.NET Web app and another instance of Visual Studio, create a WPF Client project try adding the same service reference. It says "An error (details) occurred while attempting to find services at "http://localhost:56727/PropertyGoalSetterODataService.svc" When I click on "details" it says

"There was an error downloading http://localhost:56727/PropertyGoalSetterODataService.svc/_vti_bin/ListData.svc$metadata'."

The request failed with the error message: <lots of HTML...> The server encountered an error processing the request. See server logs for more details.

(3) OK, I looked at the event viewer and the Internet Information Services Manger and could not find any logs for IIS. Can someone remind me how to do this?

(4) This does not work either. Can someone guide me on making this work and looking at the IIS error logs?

Thanks

Siegfried

 


siegfried heintze






ADO.Net Data Service update for framework 3.5 sp1 problem

ADO.Net data services error in Two format (XML & JSON)

$
0
0

Hi

I am using ADO.Net Data Services(ODATA v1) in my application with .net framework 3.5 & VS 2008.

So basically i couldn't use few things like $select with odata v1.

Error returned from the service is in different formats for different scenario.

For E.g.,

Assume i have a table name Reports

I have added accept header as application/json to the request

=> for URL with odata query is,

      http://localhost/DataServices/ReportService/Reports?$select=ReportId,ReportName

      In this case, since select is not supported ,it will throw error'The query parameter '$select' begins with a system-reserved '$' character but is not        recognized.' This error is thrown in xml format

=> for below URL,

      http://localhost/DataServices/ReportService/Reports?$top='alphabets'

     in this case, error will be "Format is not correct" . This error is thrown in Json format.

Why the error format is not consistent.?

Dynamic oData server

$
0
0

Hello,

I am in the need of creating dynamic oData server. It's easy to implement static by using Entity Framework and WCF Data services. Right now there are one foreign process, which creates some tables in DB and I want my oData server to expose these newly created and filled tables after the process has finished. If needed, I can modify that process to set up some configuration options or something. To clarify my question, I provide you with some pseudocode, which I want to implement if possible:

Dim em as EntityModel
Dim infoData as DataTable = GetInfoData() // Information about Entities I want to create

for each row as DataRow in infoData.Rows

Dim Ent as Entity = em.CreateNewEntity(row("EntityName")) // Create this entity
Dim ColData as DataTable = GetColData (row("EntityId")) // Information about entity columns I want to create

for each colInfo as DataRow in ColData.Rows

Ent.AddProperty (colInfo("ColName"), colInfo("ColType")) // Add columns to Entity

next for

Dim data as DataTable = GetData(row("EntityId")) // Not sure if this part is needed, becasue here I can bind to view or procedure or some other data from DB

Ent.DataSource = data
em.AddEntity(Ent) // Add newly created Entity to DataModel

next for


Sending large files - RequestEntityTooLarge

$
0
0

I have a WCF data service that works fine for fetching and updating data. The issue I have is when I try and send a large (ish) file. I've written a test client that sends a 40Kb file. This works fine, but as soon as I increase the file size to something like 400Kb, I get the error message "RequestEntityTooLarge".

I've read loads of info about this and practically all solutions are different, but they are all suggesting increasing configuration settings such as maxReceivedMessageSize, maxBufferSize etc.

I've tried setting various combinations of these to 200Mb and I still get the error. As a test, I also tried setting these to 20Kb and I could still upload a 40Kb file (suggesting they actually have no impact on the size of file I can upload).

I have been making all my configuration changes in the web service, but do I need to alter some settings in the client? From what I've read, I think this might be my issue, but I can't figure out how the client application configuration should look. Does anyone have a Wcf data service that can receive files over 100Kb and, if so, could they provide a full client config file please? Thanks

WCF data service returns the feed that is not valid xml

$
0
0

I created WCF data service based on the entity frame created by EF 5.0. There is no problem query data service in my console application since the feed is serialized to classes. However, I want to query my WCF data service in BizTalk 2010. I created custom behavior to modify URI. I noticed the feed coming back is not validate xml. For example, I have uri
http://localhost:12345/FXDataService.svc/Shipments(1)?$expand=ShipmentHeaders, and the returned feed contains things like:

<entry xml:base="http://localhost:12345/FXDataService.svc/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" m:etag="W/"X'00000000000019D6'"">

How do I solve this problem?

Thanks in advance!!!

Wanted: Help Understanding Self Tracking Entities in WCF RIA

$
0
0

In the book "Programming Microsoft SQL Server 2012" page 577 they compare WCF Data Services and WCF RIA services and claim that the advantage of WCF RIA is that it supports "self-tracking entities, synchronized client/server logic and much more, particularly with Silverlight."

Since that book does not help me understand self tracking entities, I turned to "Programming Entity Framework" page 489 where it says "In addition to using your own POCO classes in WCF services, Microsoft provides a specialized POCO template the creates what are called self-tracking entities. This templates creates enhanced POCOs, which include state properties and some other specialized interfaces  and functionality that allow state information to easily move between the client and the server without the author of either the service or the client app having to work out the logic of maintaining state information".

What the heck does that mean? Does that mean that after I use Silverlight two-way binding on a field in my Silverlight GUI that will synchronize the value in the Silverlight GUI with the data member in my C# class, the self tracking entity feature will automagically update the database via the Silverlight WCF RIA too? Now suppose I have to of my customers looking at the same data records and one user modifies a field, will it show up as modified in the other persons Silverlight display? Is this notion of Self-tracking entities redundant with the first book saying that WCF RIA also has "synchronized client/server logic and much more"?

Thanks

Siegfried


siegfried heintze


DataSvcUtil - getting error 0063: Precision facet not supported for data type of String

$
0
0

Whenever I attempt to run DataSvcUtil against a Data Service (version 5.0 of WCF Data Services), the proxy generation fails with the error message:

error 7001: Schema specified is not valid. Errors:
(0,0) : error 0063: Precision facet isn't allowed for properties of type String.

Any ideas? The Data Service is built using VS2012, Entity Framework 5.0 and WCF Data Services 5.0. Client is a WPF client built using VS2012. I have tried adding a service reference, as well as directly using DataSvcUtil to generate the CSharp file. Both methods give the same error.


WCF Data Services error - entities with more than one EntityKey

$
0
0

Hi

I developed a WCF Data Service application for the learning purposes. I used EF and created my entities from Northwind DB. WCF Data Service gives me an error like this,

The server encountered an error processing the request. The exception message is 'On data context type 'NorthwindEntities', there is a top IQueryable property 'CustomerCustomerDemoes' whose element type is not an entity type. Make sure that the IQueryable property is of entity type or specify the IgnoreProperties attribute on the data context type to ignore this property.'. See server logs for more details

I checked the CustomerCustomerDemoes table and found that it has a combined primary key in the other terms the entity has more than one EntityKey. Just to make sure I deleted the table and run the application it worked well.

Again I added another table with 2 entity keys the same error popped out with related to that table.

How to handle the scenarios like this in WCF Data Service, such that dealing with entities with more than one EntityKey.

Thanks in advance. :)


My blog : http://thuruinhttp.wordpress.com

wcf data services Problems

$
0
0

http://msdn.microsoft.com/en-us/library/dd728279.aspx

shows 

This XML file does not appear to have any style information associated with it. The document tree is shown below.    

<servicexml:base="http://localhost:12345/Northwind.svc/"><workspace><atom:title>Default</atom:title><collectionhref="Customers"><atom:title>Customers</atom:title></collection><collectionhref="Order_Details"><atom:title>Order_Details</atom:title></collection><collectionhref="Orders"><atom:title>Orders</atom:title></collection></workspace></service>

http://localhost:12345/Northwind.svc/Customers

after  this given link to browser it shows 

Customers

      Saturday, May 18, 2013 ( 91 Times)

it wont show any data base tables values

how to Asynchronously call a stored procedure in wcf-data-service from a windows store app

oData Feeder of a database which will be changed dynamically

$
0
0

I am creating a oData Feeder using WCF Web Services and Entity Data Model.

The problem I am facing is how to use the Entity Data Model with a database which structure will be changed dynamically.

In my case, I have some base tables that have fixed table name and columns, and some flexible tables which will be named dynamically and have various number of columns as well.

The flexible table will be generated using the data in base tables.

Here is my question.

1. Could I use Entity Data Model with such databases? and How could I accomplish it?

2. Is there any other framework instead of Entity Data Model?

Regards,

Secure oData Feeder based on SQL Role settings

$
0
0

I am creating a WCF data service with Entity Data Model.

In my Entity set, there are 3 view available (e.g. vwSales, vwCustomer, vwAddress)

For security reason, I want to show vwAddress only for managers not for all employee.

Questions is

1. Is it possible to make data service run as the user who connected, so that SQL can deny/accept the access based on the Role settings?

2. Entity Data Model will return the object name(in my case, 3 views) when user access to "http://server/.../....svc". Is it possible to restrict the visibility of each objects based on SQL Role settings?

Regards,

Viewing all 877 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>