Web API + PowerPivot with dynamic entities - c#

Since ASP.Net 2012.2 was released I have been attempting to create a Web API which returns OData which in turn can be consumed by PowerPivot. I have this working with a predefined model.
However I have a scenario whereby I will not know the number of properties prior to the request being made. What I would like to do is be able to execute a stored procedure to get a DataTable and be able to return the contents of this DataTable as odata.
My initial attempts with returning an IQueryable<DataRow> ended up with the following response.
Response, Status=406 (NotAcceptable), Method=GET, Url=http://localhost:43438/odata/Products, Message='Content-type='none', content-length=unknown'
I have since attempted to use ExpandoObject to create a dynamic object to represent the contents of the DataTable however this also gives the response above.
Is there a feasible way to use a dynamic number of properties and serialize this to OData?

You should build an EDM model and add an OData route. Refer to this blog post for the 3 steps to do to expose odata services.

Related

Simple Azure Table Service front-end for jQuery site

I'm developing a jQuery website that will display a single record from my Azure Table Storage (ATS) account. I don't want to use jQuery to directly access the table, since that would require disclosure of my ATS account name and key in the jQuery code. I've tried to find a simple C# web service example project that would be the interface, but everything I can find is much more complicated than I need.
This web service will need just one API that jQuery will use: it will be passed two strings: the Partition Key and the Row Key for ATS, which will exactly match with an existing record in ATS. The result returned will be a string that jQuery will convert using JSON.parse() after it is received. If no record is found with the Partition and Row Keys passed in, an empty string should be returned.
If you know of an example of a simple C# web service that I could use as a starting point, I would greatly appreciate a link to it. It's been many years since I developed with C#, and the complicated nature of the table service API with all the associated crypto, hashing, signatures, etc. have left me confused.
Edit: I now realize that maybe both my jQuery code (providing the web UI) and the C# (providing the ATS interface) might work together in one .NET solution. I'm currently running the jQuery UI app standalone in its own .NET solution, due to my path of fumbling around trying things out.
I don't want to use jQuery to directly access the table, since that would require disclosure of my ATS account name and key in the jQuery code.
It seems that you do not want jQuery client directly make a GET request to query entity via table service Rest API, and you’d like to create a backend service for querying entity in table. As maccettura mentioned in comment, you can create a ASP.NET Web API project and do Query Entities operation in controller action.
[Route("queryentity/{pk}/{rk}")]
public CustomerEntity Get(string pk, string rk)
{
//you can install [Azure Storage Client Library for .NET](https://www.nuget.org/packages/WindowsAzure.Storage/)
//and then create a retrieve operation and pass both partition and row keys to retrieve a single entity
//TableOperation retrieveOperation = TableOperation.Retrieve<CustomerEntity>(pk, rk);
//or
//make [Query Entities](https://learn.microsoft.com/en-us/rest/api/storageservices/query-entities) operation as you did
return myCustomerEntity;
}

how to run CURL commands using c#? [duplicate]

This question already has answers here:
C# - How to make a HTTP call
(3 answers)
Closed 7 years ago.
i want to get the data from elastic search using NEST but we are unable to write more consistent queries using nest.
so i want to write a url and get the json data from the CURL command and use it building my UI.
SO how can i do this using c#?
While it is a duplicate I wouldn't call out to another program just to hit a url.
Just use WebClient or WebRequest (difference)
curl is a linux tool to transfer data from & to servers through URLs.
elastic search is a full-text search engine with a RESTful web interface.
nest is a library that abstracts the REST api for you, if you say the abstractions do not fit your needs, you don't need to fall back to another command line program to query a REST server... if you're in a programming language that can do this easily and a lot more!
You can query REST server using C# just fine. This is the API spec:
https://github.com/elastic/elasticsearch/tree/master/rest-api-spec
You can write your own REST webclient:
Create a URL request and then submit the request using HTTP GET or
POST protocol . When the response data is returned, you must serialize
the data against a set of data contracts. As REST Services add new
functionality, these data contracts may need to be updated. A benefit of
working with JSON serialization rather than XML serialization is that
changes in the schema rarely cause issues for existing applications.
For instance, if a new property is added to the REST Services, an application that uses the old data contracts can still process a response without errors; however, the new property will not be available. To get the new property, you must update the data contracts. In order to make use of JSON serialization in .NET, use the DataContractJsonSerializer by referencing the following libraries in your project:
System.Runtime.Serialization
System.ServiceModel.Web
Source:
https://msdn.microsoft.com/en-GB/library/jj819168.aspx

Parsing Data in Xamarin Forms

I would like to get the names in collection href(CustomerDemographics, Customers, Employees, Order Details) to populate a listview. I would like to know how to parse these information in Xamarin platform or C#.
I am quite new on this environment. I have experience how to parse json data in native ios with objective c, but it is the first time I see this type of data.
From the attached image it seems that you're requesting the service document of the OData service. Namely the http://host/service/ endpoint of the service. If you would like to get the content of the collections, you should append the names of the collections to the end of the service document URL, such as:
GET http://host/service/Categories
GET http://hsot/service/CustomerDemographics
The format of the response payload depends on the protocol version of the OData service. If you are talking to a OData V4 service (it actually seems a lot like you are querying the Northwind OData V4 sample service: http://services.odata.org/v4/northwind/northwind.svc/), the response payload will be in JSON format and you can use the ways that you are familiar with to parse the response.
In addition, I would recommend you go through the basic tutorial on OData.org so that you can get a better grasp of OData requests: http://www.odata.org/getting-started/basic-tutorial/

Getting data from MS Database using Objective C?

So I've been doing research and I know that I will need to create a aspx script and run a query in aspx. Then convert the data into XML format for objective C to parse through it.
My question is can anyone elaborate a little bit more? I have little knowledge of xml and aspx.
For example example.com/test.aspx queries a user table, then I can get it to display on the browser. But what next? Convert it to xml format? Then how would my app retrieve the xml?
Thanks
Check out asp.net web api - this covers how to expose CRUD operations. The server web-api would either use ado.net to query the database directly and populate objects that then get serialized over the wire or you could use something like the entity framework or something like NHibernate to get the objects from the DB.
In iOS/Cocoa objective-c you would use the NSURLConnection to make a request to the web api server.
If the server is configured to return XML (your request sets accept header to application/xml), then in objective-c you would use NSXMLParser.
But, the more web friendly/modern approach is the http server could return json (request sets accept header to application/json) as the data and in iOS 5 and beyond, there's a JSON parser: http://www.raywenderlich.com/5492/working-with-json-in-ios-5

WCF 5 - OData 3 using POST

I have a WFC Data Service using OData v3. Following REST specification I created a method invoked by POST that adds an entity (a Client in this case) using Entity Framework.
Everything works great and adds as expected but the thing is I'm not pretty comfortable passing all the parameters I need using the query string, meaning the "typical" POST is usually application/x-www-form-urlencoded and sends the parameters in the request body instead of the query string. WCF Data Services don't seem to allow this in a relatively straightforward way.
Are there any major drawback/security issue (besides the obvious size limitation of the query string) using the query string that I should know of? Can I send parameters in the request body and use application/x-www-form-urlencoded without jumping through millions of hoops?
It just doesn't feel right to use the query string for everything.
The standard way of creating entities using OData is to send a POST to the entity set URL (of the entity set you want the entity to insert into). That POST has the entity in its body either as ATOM or JSON payload. http://www.odata.org/documentation/operations#CreatingnewEntries
Using service operations to create new entities is definitely possible, but it's not that common. It's currently not possible to send the parameters to the service operation inside a body (without some serious hacking).

Categories

Resources