Wednesday, June 25, 2008

My blog was forward to Microsoft (MS Israel Community)

Hi All,
I forward my blog to MS Israel Community.

My new blog URL is: Rotem Bloom's Blog.

I want to say many thanks to Guy Burstein that helps me open the new blog.

Wednesday, June 18, 2008

Assembly Information work under .NET 2.0

Hi All,
The Assembly Information tool is now also work under .NET 2.0.

You can download the setup from codeplex on the link below:
Assembly Information work under .NET 2.0

Tuesday, June 17, 2008

WCF Practices: Single point for WCF proxy calls

Hi All,
Let's say you want that all your WCF proxy calls will come from one function. This could be very useful and save a lot of code.
For example you can write your proxy exception handling in one place.

Here is the code example that work on .NET framework 3.5 only:

// The public function that execute the WCF proxy call
public void WCFProxyCall()
{
CreateConferenceRequest r = new CreateConferenceRequest();

Func createFunc = a =>
proxy.CreateConference(a);

CreateConferenceResponse ci = ProxyWrapperOperation(createFunc, r);
}


// This is the single point function for the entire WCF proxy calls
// Here you can write code for all your WCF proxy calls.
private TResult ProxyWrapperOperation(Func operation, T parameter)
{
TResult result;
try
{
result = operation(parameter);
}
catch (TimeoutException timeProblem)
{
proxy.Abort();
throw;
}
catch (FaultException unknownFault)
{
throw;
}
catch (CommunicationException commProblem)
{
proxy.Abort();
throw;
}

return result;
}

Sunday, June 15, 2008

.NET Assembly Information Tool is now on codeplex

Hi All,
I wrote a nice .NET tool that display .net assembly information like:
1) Compilation mode Debug\Release.
2) .NET Assembly full name
3) .NET Assembly references

You must have .NET framework 3.5 install in order to work with .NET Assembly Information tool.

How to use:
After the installation you can point on any .NET Assembly (DLL), press right click and press on the new menu called: "Assembly Information".
A popup window with useful information on your Assembly will pops.

You can find it under:
.NET Assembly Information

Monday, May 12, 2008

svcutil with /r does not work for MessageContract

Hi,
I was trying to generate WCF proxy (Client) using svcutil.exe from Visual Studio 2008. I also need to use the /r parameter of the svcutil.exe so the generated proxy code will not include the objetcs from my other internal assemblies.
The command I use is something like:
svcutil.exe /async http://localhost:8080/MyService /r:"C:\My.dll" /tcv:Version35 /out:MyClient.cs

I saw that if my .NET MessageContract objects on My.dll still exists on my generated proxy, so I have to change these objects to DataContract objects and then the generated proxy was correct.

You also need to remember that if your internal objects (on My.dll) contain objects form other internal assembly, You have to include this dll also in your svcutil command. So you new command will look like:
svcutil.exe /async http://localhost:8080/MyService /r:"C:\My.dll" /r:"C:\MyOtherObjects.dll" /tcv:Version35 /out:MyClient.cs

Your,
Rotem

Monday, May 5, 2008

Increasing WCF Client Applications Performance

Some times your WCF client object are created on the Middle-Tier of the application.
This scenario leads for creating many WCF client objects quickly and, as a result, experience increased initialization requirements.

There are two main approaches to increasing the performance of middle-tier applications when calling services:
1. Cache the WCF client object and reuse it for subsequent calls where possible.
2. Create a ChannelFactory object and then use that object to create new WCF client channel objects for each call.

Issues to consider when using these approaches include:

- If the service is maintaining a client-specific state by using a session, then you cannot reuse the middle-tier WCF client with multiple-client tier requests because the service's state is tied to that of the middle-tier client.

- If the service must perform authentication on a per-client basis, you must create a new client for each incoming request on the middle tier instead of reusing the middle-tier WCF client (or WCF client channel object) because the client credentials of the middle tier cannot be modified after the WCF client (or ChannelFactory) has been created.

- While channels and clients created by the channels are thread-safe, they might not support writing more than one message to the wire concurrently. If you are sending large messages, particularly if streaming, the send operation might block waiting for another send to complete. This causes two sorts of problems: a lack of concurrency and the possibility of deadlock if the flow of control returns to the service reusing the channel (that is, the shared client calls a service whose code path results in a callback to the shared client). This is true regardless of the type of WCF client you reuse.

- You must handle faulted channels regardless of whether you share the channel. When channels are reused, however, a faulting channel can take down more than one pending request or send.

Link to MS article:
Middle-Tier Client Applications

Best Practices: How to Dispose WCF clients

Use of the using statement (Using in Visual Basic) is not recommended for Dispose WCF clients. This is because the end of the using statement can cause exceptions that can mask other exceptions you may need to know about.

using (CalculatorClient client = new CalculatorClient())
{
...
} // <-- this line might throw
Console.WriteLine("Hope this code wasn't important, because it might not happen.");

The correct way to do it is:
try
{
...
client.Close();
}
catch (CommunicationException e)
{
...
client.Abort();
}
catch (TimeoutException e)
{
...
client.Abort();
}
catch (Exception e)
{
...
client.Abort();
throw;
}