Thursday, December 13, 2018

Get raw query from Elasticsearch NEST client

https://stackoverflow.com/questions/28939022/get-raw-query-from-nest-client
var json = elasticClient.RequestResponseSerializer.SerializeToString(request);
Great for debugging and finding out what json you are sending.

Wednesday, December 12, 2018

DateTime and DateTimeOffset

Choosing between DateTime, DateTimeOffset, TimeSpan, and TimeZoneInfo

DateTime.ToLocalTime

Utc This instance of DateTime is converted to local time.
Local No conversion is performed.
Unspecified This instance of DateTime is assumed to be a UTC time, and the conversion is performed as if Kind were Utc.

DateTime.ToUniversalTime

Utc No conversion is performed.
Local The current DateTime object is converted to UTC.
Unspecified The current DateTime object is assumed to be a local time, and the conversion is performed as if Kind were Local.

Tuesday, June 5, 2018

ServiceBus Serialization Scenarios

ServiceBus Serialization Scenarios.
Use BrokeredMessage with explicit json to understand whats going on.
E.g. for using in Azure functions
class MyData
{
 public string name {get;set;}
}

// Sender
[FunctionName("Send")]
public static void Send(..., [ServiceBus("%Topic%")] out BrokeredMessage brokeredMessage, ...)
{
 ...
 MyData myData = new MyData();
 string bodyJson = JsonConvert.SerializeObject(myData);
 brokeredMessage = new BrokeredMessage(bodyJson);
 brokeredMessage.Label = "My routing info";
 ...
}

// Receiver
[FunctionName("Receive")]
public static void Receive([ServiceBusTrigger("%Topic%", "%Subscription%")] BrokeredMessage brokeredMessage, ...)
{
 ...
 string bodyJson = brokeredMessage.GetBody<string>();
 MyData myData = JsonConvert.DeserializeObject<MyData>(bodyJson);
 ...
}

If you want to send a test message using Service Bus Explorer in the send message dialog just paste the json e.g. {"name":"Andreas"} into Message -> Message Text and then set Sender -> Body Type to String (i.e. not Stream). Set the Label as well if you want to route the message.
ServiceBus Serialization Scenarios
Messages, payloads, and serialization
Azure Service Bus bindings for Azure Functions

MVC json DTO

If you got a DTO and want camelCase json when returning data.

Is there any benifit in using DataContract and DataMember attributes while working with Asp.net Web API?

Is there a way to alias response model properties in ASP.Net Web API

JSON and XML Serialization in ASP.NET Web API