I created a WCF Dataservice and tested using Postman (Chrome extension) which work fine. Then I added the service reference which points the WCF Dataservice in my client C# library.
When I call the Transactions DbSet on my DataService, I get the number of transactions properly however all items in the list were overwritten with the last item in the list. i.e if I have 10 transactions in the database, I get 10 in my list but the data in all items are same which is the last item in the database.
I am using simple LINQ to get the data as shown below
List<Transaction>() tempList = new List<Transaction>();
tempList = GetContext().Transactions.ToList();
The weird part is when I catch the query that runs on database using the Fiddler, the output from the database is fine, which means something is happening in my client and overriding all the items in the list with the last item.
Can anyone point me how to debug this or how can I catch who is overriding my list.
Got it..found that there is no UNIQUE key on the table, so from client upon deserializing its adding the last found item to the list
Related
I have created a service that has several void/bool methods() and when I refresh the service reference on the client I can see those methods.
The issue is when I add a method with a custom type and supply it with all the correct tags datacontract/datamember, when I update the service reference again on the client nothing gets built not even the existing methods. No errors are spit out and I'm stuck with no clues on where to turn.
I also tried pulling in the service1 that is created as an example in to my client and it didn't get the composite type either.
The client is MVC4. The entire stack .net 4.
EDIT
After further review and testing, the problem is not with the service project or any of the data contracts. It is with the mvc project generating the reference.cS file. It is not generating the file or reporting an error on why it's not creating it. I proved this by opening a brand new empty mvc project and added the service reference and it generated everything perfectly.
I'm new working with WCF and so far I understand the basic to create a web service with it, but I have a problem with some of my methods.
I have my services defined as follows link and my web.config is like this. My model has 5 entities, one of them is not related to the rest for the moment, the other four are related among them, my model looks like this. I have endpoints that do the usual CRUD operations, there's no problem inserting, updating or deleting, but when I tried to get the list of Eventos, Regiones, Clusters and Dispositivos, the method fail and doesn't return anything.
The funny part is that if I generate the database from my model again, restart the service and reinsert the data again, I can get the data from the endpoints with no problem. But if I stop the service and restart it againg, then it fails once again.
This only happens with the four entities that are related, all the endpoints for Usuarios work fine, but for the other 4, the endpoints fail only when I'm trying to retrieve all of the entries or just one entry of an entity. If I try to insert, update or delete an entry from any of these entities there's no problem, the problem is only present when I try to get the list of entries or just one entry.
For example if I try to access the url 127.0.0.1:81/SismosService.svc/region/index it returns in Google Chrome Error 324 (net::ERR_EMPTY_RESPONSE), but that doesn't happen with 127.0.0.1:81/SismosService.svc/usuario/index, that url return me the correct JSON object I'm expecting which looks like this:
{"Meta":{"Method":"GetUsuarios","Status":"ok"},"Response":[{"ApellidoM":"Mendoza","ApellidoP":"Arvizu","CreatedDateTime":"/Date(1357947261710-0600)/","Nombre":"Uriel","Password":"uriel88","UpdatedDateTime":"/Date(1357947261710-0600)/","UserName":"uriel88","UsuarioId":1},{"ApellidoM":"Mendoza2","ApellidoP":"Arvizu2","CreatedDateTime":"/Date(1357947273070-0600)/","Nombre":"Uriel2","Password":"auam","UpdatedDateTime":"/Date(1357947273070-0600)/","UserName":"auam","UsuarioId":2}]}
Why are these endpoints failing?
This was caused by trying to send objects with circular referencing, since EF creates the objects for a determined entity, if for example you want to send an object foo of type EntityA, which has a property of type EntityB, that property will have a property of type EntityA that references the original object foo, this creates a circular reference which can not be parsed into JSON by the service.
What I did was the following: To create a new instance of type EntityA and assign to each of its properties the values you're interested from the foo object, leaving the objects that creates a circular reference as null.
I have searched google and exhausted a fair bit of my time trying to figure out what is going on with my WCF and client Windows form app.
I am continuously getting the following error
"Unable to set field/property Ingredients on entity type Datalayer.UnitOfMeasure. See InnerException for details."
...
inner exception is
"An item cannot be added to a fixed size Array of type 'Datalayer.Ingredient[]'."
Stack Trace -
at System.Data.Objects.Internal.PocoPropertyAccessorStrategy.<AddToCollection>b__0[T](Object collectionArg, Object item)
at System.Data.Objects.Internal.PocoPropertyAccessorStrategy.CollectionAdd(RelatedEnd relatedEnd, Object value)
The way I have configured my solutions I have a WCF web-service which reference my DataLayer class library, I have a windows app (test app) which references the WCF services as well as DataLayer project.
If I don't reference the DataLayer in my test app, this issues does not occur however I lose the ICollection<Ingredient> to simple Ingredient[] array. Now as you can see this becomes a coding pain to initialize the array every time.
Any idea anyone? thanks in advance.
I was running into this exact error, but the accepted answer wasn't quite the solution I needed. It turns out that the client was sending a List<Order> up to my WCF service, but since the Customer.Orders property was defined as an ICollection<Order>, the WCF deserializer deserializer just deserialized it in the simplest form it could, which was an array of type Order, i.e., Order[].
The only solution I was able to come up with was to change the property in question on my POCO objects from an ICollection<Order> to a HashSet<Order>. See Stop WCF Deserializing Empty ICollection into Zero Capacity Array for a few more details.
When you are adding reference to WCF service in the test using 'Add Service Reference' there is a option to configure the default collection type for the generate proxy on the client. The default i think is array, you can change it to a generic list.
In case you are using svcutil,that too allows the same thing.
Weird. I had this same error, and was doing the right thing, calling "ToArray()". Changed it to "ToList()" and it started working fine.
I've seen a lot of articles about retrieving the identity ID of a new created record using other DBs and frameworks. I am creating a record in code in a Silverlight RIA Services app. I perform the Add method and then do a SubmitChanges on the DomainContext, but I do not see the ID. It comes up as 0. How do I get the new ID? Thanks.
Try this
private void OnProfileCreateCallback(SubmitOperation submitOperation)
{
submitOperation.ChangeSet.AddedEntities.First().GetIdentity()
....
}
OnProfileCreateCallback is a call back method used in context.submitchanges(...)
You can put custom logic if you are having multiple records as part of add.
I have created a datacontext in my silverlight app which utilized "WCF dataservices" to pull out data from custom Odata repository which in turn takes the values from an XML file, the XML file values keep changing since they represent live data, so the question is :
1) when the original data values change can this be reflected automatically on the context ! (I'm implementing "INotifyPropertyChanged" in the mapped class in the WCF service, but still no effect !)
2) when a record is deleted from the original XML, the context records will not be affected until I clear the data and reload them again !.
anyone can help me with this !
The WCF Data Services client needs to query the OData service to get the new values if the original data values are changed/deleted.
DataServiceCollection implements INotifyPropertyChanged to alert the context when objects are added to or removed from the collection, but it is not aware of any original service data changes on the service side.
Hope this helps.