November 25, 2010 WCF No comments
November 25, 2010 WCF No comments
Sessions and Instances
Per Call*
On each request to service (each time we use service method) new instance of Service implementation will be generated. Often this is not suitable for us when we want some to keep track of actions (transactions) or when we access some critical resources.
Per Session*
Is default Session mode. (BTW book on preparation to 70-503 has mistake mentioning that PerCall is default). In this case client knows that Service provides sessions. We can also highlight requirement of using sessions by marking contract with SessionMode.Required. Session is kept with identifier assigned to you proxy class, that you use at client.
We also have possibility to share same instance of service by passing additional identifier in message header that goes from Client. For that we would need to implement IInstanceContextProvider.
Singleton
Is more rarely used Session mode, but it might be useful when we access one super-critical resource. Plus to that that one plus in using this session mode – possibility to create instance of service even before service host has been created.
* Pictures, but not text below, were taken from training kit book for ms exam 70-503: Link
November 22, 2010 WCF 4 comments
public class CalculatorService : ICalculatorService { public int Execute(int a, int b, string operation) { Console.WriteLine("Received request: ({0}{2}{1}=?)", a, b, operation); int result = -1; switch (operation) { case "+": result = a + b; break; case "-": result = a - b; break; case "*": result = a * b; break; case "/": result = a / b; break; default: Console.WriteLine("Our calc executed hara-kiri."); Process.GetCurrentProcess().Kill(); break; } return result; } }
public class CustomEndpointBehavior : IEndpointBehavior { public void Validate(ServiceEndpoint endpoint) { return; } public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters) { return; } public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher) { return; } public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime) { foreach (var clientOperation in clientRuntime.Operations) { clientOperation.ParameterInspectors.Add(new OpParameterInspector()); } } } public class OpParameterInspector : IParameterInspector { public object BeforeCall(string operationName, object[] inputs) { switch (operationName) { case "Execute": VerifyExecuteParams(inputs); break; } return null; } private void VerifyExecuteParams(object[] inputs) { if (new string[]{"+", "-", "*", "/"}.Where(x => x == (string) inputs[2]).Count() == 0) { throw new ArgumentException("Your operation should belong to folowing list: '+', '-', '*', '/'. Please verify and try again."); } } public void AfterCall(string operationName, object[] outputs, object returnValue, object correlationState) { return; } }
November 14, 2010 Book Reviews, Certification, WCF No comments
August 19, 2010 DevMeeting, Presentation, Success, WCF 1 comment
Hello, today I performed presentation on Windows Communication Foundation and it went extremely well. People were interested in topic and it smelled in the air.
Why am I happy with this meeting?
People were listening very-very attentively! It is the best gift to the speaker. Many thanks to today’s attendees! You made this presentation awesome!
What was the agenda?
For today I planned to have “Getting Started” session, where I decided to talk in general what is WCF and then proceed to basic concepts of it, like ABC.
In DEMO 1 (Damn it! Let’s write some code!) I created ever simplest WCF library and simple Contract that exposed todo list functionality. Then I brifly showed configuration and we started wcftestclient.
In DEMO 2 (Damn it! Let’s configure it!) I talked a lot about endpoints and how we can configure them. After I created a lot of them it was highlighted that changing the way how our service works by configuring and not changing the code is the key feature of WCF. WCF is indeed unified framework that allows us has one logic, but different exposing to the real world.
In DEMO 3 (Damn it! Let’s use & host it!) I created very simple console application that was able to send todo item to the service. It went with some exceptions thrown into console, but people liked it and besides after that I created SuperTodoServiceClient and it worked well. Also we voted were do we want to host our service for the long time. Most decided to host it under IIS. Till the actual hosting all went well, but then suddenly it didn’t work under IIS. Reason was very simple – since my machine has brand new OS, IIS was not configured properly.
What’s next?
Also I’m planning to have another meeting on the WCF. This time it will be “Advanced”. In that session I would like to show some real-world examples. Also I’m going to prepare to the 70-503 exam (on WCF), so I might get some interesting topics from the training kit to show on the meeting.
Presentation
More and more I start disliking ppt files. But anyway to have some visual appearance of presentation I created ppt file (maybe finished with it at 5:30 am so don’t kill me if it is “poor”). Btw, having ppt has some plus – I can put my blog’s logo and URL :)
Guys, looking forward to hear from you! Will appreciate any of your comments.
March 3, 2010 IDE, WCF, Workaround No comments
If you have no “Edit WCF Configuration” in the context menu on right click on the App.config.
I’m talking about this one:
Go to Tools -> WCF Service Configuration Editor
Open it and then close.
This is funny and strange solution to our issue.