I am using MS Web API 2 to receive calls from our web page using ajax.
Then I have 2 classes: subscriber and externalSubscriber. Subscriber contains very basic data like a name and id. External subscriber inherits from subscriber and adds basic data like address and email. I have one api method to edit the data of a subscriber defined like this:
public IHttpActionResult PutSubscriber(int id, Subscriber subscriber)
In our page I create a json string using the data provided which leads to it ether being a external or a normal subscriber.
I am able to post to this function using both but with an externalSubscriber object the added data gets lost and trying to cast from subscriber leads to an error.
my question is if anyone has any experience with this issue and if there is another way to fix this besides creating a specific function for putting a external subscriber.
I have got it to work by using the information provided on the following pages:
http://www.newtonsoft.com/json/help/html/SerializeTypeNameHandling.htm
Polymorphism in Web API: Single endpoint possible?
First I set the json setting:
jsonsettings.SerializerSettings.TypeNameHandling = TypeNameHandling.Auto;
then setting the type of the json object before sending with ajax using
jsonObject { '$type' : .Models.ExternalSubscriber, solution.project', ....}
after this I am able to cast the incoming Subscriber to an ExternalSubscriber and access its properties.
Related
I'm following this tutorial for push notifications, and I'm stuck at the part where it says
To trigger a push message, make a POST request to this URL.
I generated the public and private keys using this site and placed the public key in the applicationServerKey key before calling registration.pushManager.subscribe, and I get a properly formatted JSON response, but I'm unsure of how exactly to generate the Authorization header for use in the POST request to send a notification. Here's what the JSON response from subscribe looks like:
{
"endpoint":"https://fcm.googleapis.com/fcm/send/asdf:qwer",
"expirationTime":null,
"keys":{"p256dh":"key","auth":"auth"}
}
I surmised that the portion after /send should be placed in the to field, but I'm unsure of how to format the Authorization header. Surely I should need to use the private key in some way, but I'm not sure how.
My assumption is that I need to perform some sort of operation on my private key, the p256dh field, and the auth field, and that result will be placed in the key= field in the POST request, but I cannot find the reference for this.
Do you need to create a Firebase project to do this? I'm unsure of whether or not this is the case.
Yes, all access to Firebase products and services requires the creation of a Firebase project. You can't use arbitrary keys to invoke FCM. You must use a service account that's been granted permission to call the API.
I have the following problem.
One of the endpoints for my spring-boot controller has to return a POJO with a couple of big BLOBs plus some metadata information about those BLOBs.
We need to be able to send first the metadata information (so that UI can display it without any delay), and then send the BLOBs, all part of the same RESTful request. If we send the metadata + BLOBs all in the same response, it would impact the performance and UI will seem sluggish.
I've been exploring the Future, DeferredResult etc, but I couldn't find how a JavaScript client can benefit from them.
Ideally, the response would contain the metadata plus some uniquely generated endpoints to fetch the BLOBs that controller would keep cached for the time-being, till they are requested.
I wonder what approach I can take here?
Add #JsonIgnore annotation on blob getter inside your entity class, to avoid serialization of this field to the response json. Then add separate controller method which will retrieve the same entity, but return back the contents of the blob only.
I have a custom Odata endpoint which gets it filter via a post from the body and not the query string. At the moment all of the queries are hand coded and then fed in to the post.
I was wondering if anyone knows if I can use Breezejs just to create the query I need.
Cheers
According to the "OData AJAX" section in Controlling AJAX you'll need to make changes to your copy of data.js so that POST is used instead of GET.
If you don't care to have breeze load the data and just want to use the EntityQuery syntax to build queries you could try getting an instance of the breeze odata uriBuilder and call the buildUri method to convert the EntityQuery to an odata uri. Assuming that works, it would be a matter of grabbing the querystring component of the uri to use in your POST body.
var interfaceRegistry = breeze.config.interfaceRegistry,
uriBuilderInterface = interfaceRegistry.uriBuilder,
uriBuilderCtor = uriBuilderInterface.getImpl('odata').ctor,
uriBuilder = new uriBuilderCtor(),
uri = uriBuilder.buildUri(entityQuery, metadataStore);
There might be a better/simpler way of doing this... maybe by grabbing the uriBuilder from a breeze odata dataService instance. I don't think this is part of breeze's supported/documented public api but it sounds like it would make a nice feature suggestion to post on the user voice site.
I have a list of of data being return from a "standard" HttpGet IQueryable method from an ApiController that implements the Breeze EFContextProvider. When one of the objects references another object that has already been returned in the payload, Breeze gives me an $ref to refer to the object that was already returned.
I want the object with all related objects return explicitly, not a reference with $ref. Also, I'm not using the breeze.js library on the client side; simply making straight calls to the Controller with a web address.
I found this:
Breeze does not replace the Ref: node with its real data
which is the thing I'm looking for, but using Include on the server still doesn't return all of the data.
Any idea on how to "force" Breeze on the server side to include all related data no matter if it was returned and referenced in the payload?
Update 1
Per Steve's answer below I added the following to the BreezeWebApiConfig.RegisterBreezePreStart method in the App_Start folder:
var json = GlobalConfiguration.Configuration.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.Object;
Compiling and running produces the same output with only the $ref group instead of the full data. I'm sending a request to the server to $expand the collection. Do I need to change the SerializerSettings upon each request to the controller or will adding this to the BreezeWebApiConfig.RegisterBreezePreStart method be enough?
Update 2
I've added a CustomBreezeConfig class per the instructions at the link that Steve added in his answer. I am however using Breeze.WebApi2 so it appears that the BreezeConfig is actually in Breeze.ContextProvider. The code compiles, but I'm still seeing the same $ref for the actual object in JSON.
Do I need to include this CustomerBreezeConfig class in a specific place in my project for Breeze to use it's serializer settings?
Under WebAPI, Breeze uses the Json.NET serializer to turn the results to JSON. You can change the serializer settings (specifically the PreserveObjectReferences setting) to change this behavior.
Breeze configures it's own JSON serializer, so in a Breeze app, you'll need to configure it as described in the Breeze Web API Controller doc.
Note that, if you turn PreserveObjectReferences off, you might also need to configure the ReferenceLoopHandling setting, if you have circular reference in your object graphs (as most of us do).
I've try to pass response of facebook api request that I get it via FB JS-SDK into my flash application using external interface but I don't get what response type, it result [object object] when I print it in console but when I try type such as response.name or .id or using scope (some value display correct but some still display [object object]).
So,
First, what data type that returned by fb's response?
How I can pass it into flash apps, what about the type argument that I must set?
Then, which is the effective solution between extract the response each key that store it in an array then pass it into flash then extract again each part or send response object to flash then extract it in flash side?
I'm so confused because when I use JSON.decode method in js, it results nothing (undefined).
I'll appreciate for your attention and solution.
You shouldn't use JSON.decode your facebook data, you already get a JSON object that is ready to work with. Though flash doesn't know what is to be there in your JSON object so there will be no code snippets (consider it as a dynamic object)
For example, when you get your simple information about user*FB.api('/me'...)*, you have a .name property:
...
public function receivedResponce(response:Object):void
{
trace(responce.name);
}
...
You can get any other type of data returned by facebook request, whether it's a friend list or link to the user photo.
There's a lot of information about what fields do facebook requests return, try reading it's API guide