The default Diff/Merge Tool from Team Foundation is everything else than sophisticated… But who cares, it’s pretty easy to use your favorite Tools for Diffing and Merging. Continue reading Custom Diff/Merge Tools in Team Foundation
Roemer
There are multiple possibilities to call an Operation Asynchronous from a WCF Service:
Event Based Model
In this model, you register to a Completed
-Event and call your Operation with an Async
appended. The Callback Method is run on the same Thread that was used to call the Async Request, so you don’t need to invoke
it in case you’re modifying the UI.
Example:
public void AsyncCall() { MyServiceClient client = new MyServiceClient(); client.SomeMethodCompleted += SomeMethodCompletedCallback; client.SomeMethodAsync(<Your Parameters>); } public void SomeMethodCompletedCallback(object sender, SomeMethodCompletedEventArgs e) { MyServiceClient client = sender as MyServiceClient; if (client != null) { client.Close(); } <Your Return Value> = e.Result; }
IAsyncResult Model (Client-Side)
In this model, you call your Operation with a prepending Begin
. Note that the Callback is running on a Worker-Thread so if you’re modifying the UI, don’t forget to invoke
in the Callback.
Example:
public void AsyncCall() { MyServiceClient client = new MyServiceClient(); client.BeginSomeMethod(<Your Parameters>, new AsyncCallback(OnEndSomeMethod), client); } public void OnEndSomeMethod(IAsyncResult asyncResult) { MyServiceClient client = asyncResult.AsyncState as MyServiceClient; if (client != null) { <Your Return Value> = client.EndSomeMethod(asyncResult) client.Close(); } }
IAsyncResult Model (Server-Side)
This is the only “true” Asynchronous Model. It will run in a Server-Thread so you are able to get the status of a pending Operation or even cancel it. The implementation is more time-consuming than the other two but, in some cases, worth the effort.
I suggest you Google for some examples.
There is a very good series of posts at Dan Rigsby’s Blog
starting at this Post. Have a look at it to get more information and examples.
When you try to access a WCF-Service with your Browser you might see the following Error:
HTTP Error 404.3 – Not Found
The page you are requesting cannot be served because of the extension configuration. If the page is a script, add a handler. If the file should be downloaded, add a MIME map.
If that happens, you probably don’t have the Service Model registered with your IIS.
Here’s how to register it:
- Start the command window (cmd) as an Administrator.
- Navigate to:
C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation\ - In case you are running on a 64Bit machine, than navigate to:
C:\Windows\Microsoft.NET\Framework64\v3.0\Windows Communication Foundation\ - Run the following Command: ServiceModelReg –i
You now should be able to access your Webservice.
When developing Web-Applications with Asp.Net, you often run the Page with your Debugger and want to step thru the Code. If you hold too long on a line (default is 90 Seconds) you’ll get a Timeout and the Debugging stopps.
Here’s how you can disable that the Debugger stopps:
- Open the IIS Manager
- Go to the Application Pools
- Right-Click your Application Pool and select “Advanced Settings…”
- Search the Setting “Ping Enabled” under “Process Model”
- Set it to “false”
- Press Ok
- If you get an “insufficient permissions” Error or something, try to clear the “Read only” Flag from that File you see in the error Message.
That’s it. You can now debug as long as you want without getting a Timeout.
When working with XML, you sometimes want to save some Text into the XML.
That can lead to problems when you use special Chars which then confuses the XML Parser.
To fix that you could just use multiple Replaces over your String or just use the .Net Function:
System.Security.SecurityElement.Escape
Example:
string myText = "Hello & World! <3"; string myTextXMLSafe = System.Security.SecurityElement.Escape(myText); // myTextXMLSafe is now "Hello & World! <3"
C# 3.0 has a “nice” Feature called “Anonymous Types”.
Basically it is great for LINQ where you want to create a Type on the fly.
To create such a Type just use
var myAnonymousObject = new { Firstname = "John", Lastname = "Doe" };
Now you possibly want to extend that a little and have a Function return a List of such a Type.
You can’t use List<T> because you don’t know the Type. You could use a List<object> but that’s not nice. It’s better to use a Feature called “Casting by Example”.
An Example Function implementing this Feature could look like:
public List<T> GetList<T>(T exampleObject) { List<T> newList = new List<T>(); // TODO: Fill the List somehow return newList; }
You can then call this Function like this:
var someList = GetList( new { Firstname = "", Lastname = "" } );
Since I always forget some important things about Regex, I’ll write it down here:
Greedy vs Non-Greedy
If you have something like “hello|world|!” and you want to get only the first part before the first Delimiter (which obviously is “|”) your first try could look like:
(.*)\|
That one would match “hello|world” since by default Regex is Greedy (aka. “take as much as possible”).
The old-fashioned way was:
([^\|]+)
This one does match unless the “|” Sign is found.
Now Regex has a much nicer solution:
(.*?)\|
The added “?” makes it Non-Greedy (aka. “take as less as possible)
Non-Capturing Group
Sometimes you want to create a Group which is not captured. Just begin those Groups with an “?:” and it will not get captured.
Example:
(?:abc)
Singletons can be great. But it’s important to make sure that the Singleton really is a Singleton, even in a Multi-Threading Environment.
There are multiple possibilities to achieve this and here are my Favorites: Continue reading Thread Safe Singleton Pattern