Skip to main content

Use fastJSON with WCF (C#)

To use fastJson Serializer with WCF Web Service:
  1. Within a Web Site or App Project (VS), Add AjaxService
  2. Add:
    1. Method: Get, Use: Only to retrieve Data
[OperationContract]
[WebGet(ResponseFormat = WebMessageFormat.Json)]
public Stream TestStream(string ticker)
{
WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";
string jsonString="{\"d\":{}}";//Here you do the serialization
MemoryStream ms = new MemoryStream(ASCIIEncoding.Default.GetBytes(jsonString));
return ms;
}
    1. Method: Post, Use: Insert data / data manipulation
[OperationContract]
[WebInvoke(Method="POST", ResponseFormat = WebMessageFormat.Json)]
public Stream TestStream(string ticker)
{
WebOperationContext.Current.OutgoingResponse.ContentType = "application/json";
string jsonString="{\"d\":{}}";//Here you do the serialization
MemoryStream ms = new MemoryStream(ASCIIEncoding.Default.GetBytes(jsonString));
return ms;
}

Comments

Popular posts from this blog

Wpf, TreeView and Mvvm: Conceptual Findings (Part 1)

I have read a lot of articles, comments and how To's (see below for a brief list of links) about the use of MVVM with TreeView (WPF & C#), but none of them convince me for the proof of concept that i have in mind. Why? Because i think that the Drag & Drop operation is, only, a View Operation. As i understand the MVVM is like:  Model: Data and data extract/insert operations ViewModel: Commands, Main Logic and so on... View: User Experience After defining the concepts, i want to note something: the view can be a console application, a web page, a window application or a touch application. I'm not sure that if the view is a console app, there must be commands to handle the drag and drop operations like Sparky at al mentioned (we can have an interface defining the ViewModel and a lot of pairs classes (View & ViewModel), but then, where is the re usability of the code?) Let me be clear about something, the idea of Sparky is very interesting (and clear) so it was