Category Archives: Indigo

Sharing custom types with client and services apps? Use WCF

One of the very difficult to solve problems in .NET client & web service solutions is sharing custom objects between the web service and the client.

Here’s the scenario.

You have a business layer with some serializable objects. Let’s say the namespace is “MyLovelyBAL” and the object is “MyLovelyObject”.

You have an operation in your web service that returns one of those objects.

Now you build a client, say a Windows Forms app (“MyWinApp”) that will call into that Web Service, and you are not savvy enough to use a tool like thinktecture’s WSCF. 🙂 Therefore you “Add Web Reference” and point to the web service you built. In doing so, you are asked to give a name to the proxy. Let’s call that “MyWSProxy”.

In your WIndows Forms app, you also have a reference to the assembly that contains MyLovelyBAL.MyLovelyObject.

Now it’s time to write some code.

You instantiate the proxy and request a lovelyobject.

Dim myproxy = New MyWSProxy.Service
Dim MyLovelyBAL.MyLovelyObject=myproxy.GetMyLovelyOBject

But it fails telling you that you can’t cast a MyWinApp.MyWSProxy.MyLovelyObject to a MyLovelyBAL.MyLovelyObject.

And then you will begin on a journey to hell, which might include reading this article on Schema Providers which is not for the feint of heart.

So just forget it. It’s 2007! We have WCF.

You can go into your project where you define the MyLovelyObject class and give it a DataContract attribute and give it’s properties (that you want to expose) DataMember attributes. Your interface operation (and any operations that implement it) will return a MyLovelyBAL.MyLovelyObject object.

And when you Add Service Reference to your windows forms app, there is no namespace replacement. A “MyLovelyObject” is always coming from MyLovelyBAL and this is oh, so lovely. The way it oughtta be!

You know I learned this the hard way. And I will be seeing Michele Leroux Bustamante tomorrow who will first bop me on the head for waiting so long to use WCF and the sit me down and have me read her fabulous book Learning WCF, (which I had in my hands long enough to raffle off at VTdotNET last week BOO HOO) cover to cover. It’s about time!

PAG announces Service BAT – Guidance design and even implementation for WCF services

Ahh, I’m a day late and a dollar short. Yesterday the PAG Team announced Service BAT – Service Baseline Architecture Toolkit – that will guide and help you implement WCF and ASMX services. They have had a bunch of plumbers helping them out including Christian Weyer and Pablo Cibraro. I can’t wait to get my hands on it. This type of tooling will help take another layer of fear (and unintentional bad design) allowing WCF to be accessible to a lot more people.

Here’s Jason Blogg’s announcement.

Edward Bakker has some good details.

Don’t Forget: www.acehaid.org

WSE3 with WCF February CTP

Everything I thought I knew about how to interop messages between WCF and WSE3.0 went down the toilet with the newest bits of WCF.

Thanks to some serious counseling from William Tay this morning (who has been diving deep with WCF for a long time and has also kept up with the changes that affect all forms of interop, even WSE3.0) and then lots of hours of just trying, failing, thinking, adjusting (rinse and repeat) I finally got a WCF client app to talk to a WSE3.0 secured web service using a UsernameforCertificate binding/policy.

And yes, it’s all secured on the wire. I had every problem. Wrong X509 certificates installed, wrong encryption algorithms, hitting a few WCF bugs and more. Luckily, all of the work I have done with WSE3.0 has helped me prepare for troubleshooting this stuff. To me, that is one of the most important lessons!

Here are a few of the things I can share.

I was doing what Willie tells me is the hardest thing with interop – UsernameOverCertificate. But being bullheaded I had to go forward with it.

I tried writing my own, but didn’t understand well enough (though now I think I could tackle that) and instead used WSEHttpBinding that is a custom binding in one of the WCF samples.

That binding uses the Aes128 algorithm for it’s default security binding and secure conversation. I kept getting a message that the algorithm was insufficient to encrypt and key wrap. Changing them both to Aes256 fixed that. It took me a while to realize there were two spots to change, but I had the right idea! Uggh.

At one point, I was still getting an error, but looking at the web service’s trace, I could see that everything on that end had finally happened correctly. Therefore the problem was on the client side. Google gave me ONE response, and naturally it was from a blog post of Willie’s! He had seen a similar problem in the Sept. CTP, but it was enough to fix my problem (Feb CTP).

Since this stuff is still in flux, I think I will wait for WCF beta2 to be released before I attempt to update my article on preparing WSE3 web services for WCF. Truly the hard part (until the new bits are all sorted out) is writing the WCF client. I didn’t have to do anything to my web service to get this to work.

Willie’s got a pair of great articles on WCF on The Server Side (first, second) and I hear there’s a WSE3/WCF interop article coming soon from him as well. Lucky or the rest of us!

I will never have the deep knowledge of this stuff hat Willie and his compadres (Michele Butamante, Christian Weyer, Juval Lowy, etc.) have, but as long as I am willing to battle this stuff out so that I can share it with other programmers who are floating on the surface, I’ll keep at it.

I’ll be looking at more of this stuff in my WSE3 for WCF session at DevConnections next week. My focus is on making sure the WSE3 services are written correctly so that you can talk to them in the future from WCF. I won’t be teaching WCF. You can go across the hall to see Michele for that.



Don’t Forget: www.acehaid.org

Installation order for February CTP of WinFX

The January CTP install notes recommend installing the WinFX components before VS2005, but according to Michele Leroux Bustamante, who has done a LOT of work with WCF, if you are working with the newer (non go-live) February CTP  release, it’s okay to install all of theWinFX ontop of VS2005. This is great to know because I can store a copy of a VPC with WinXp and VS2005 already installed, then use it when testing new WinFX bits as they are released.

See Michele’s blog post for links and installation order.



Don’t Forget: www.acehaid.org

Atlas and WCF

It seems like just yesterday that I was asking around about how Atlas interacts with WS-Security and other WS* compliant web services created using tools like WSE or WCF. And woudntchaknowit! The Atlas version that was released just yesterday has WCF extensions built right in for seamless communication with WCF.

Oddly, I came across the link on the Atlas site today not knowing that it wasa brand spanking new page, and therefore was feeling  a bit embarrassed that I had completely missed this before! 🙂

It wasn’ until I saw Steve Maine’s post that I realized it hadn’t been up there for long!

Don’t Forget: www.acehaid.org

WCF Article Series by the pros coming up in CoDe Magazine

I’m looking at Rod Paddock’s editorial in the current CoDe Mag issue. This is the future tehcnologies issue wiht articles on WPF, LinQ and Ajax. In the editorial he says that there is going to be a 6 article series on WCF starting with the next issue. I’m really looking forward to this. Especially considering who is going to be writing some of these: Michele Leroux Bustamante, Juval Lowy, Christian Weyer.

Don’t Forget: www.acehaid.org