Welcome to MSDN Blogs Sign in | Join | Help

Three and a half months ago I switched teams. I'm now part of the "Oslo" Modeling Languages team.

If you want to know more, check out these 2 new blogs that we launched:

Justin Ng has started an MSDN blog. Justin and I work together on the Zune Services team.

Testing a custom moniker link in community server 2.0

Ali Pasha has an interesting post about some issues you can run into when you use Visual Basic and svcutil.exe and I thought I'd write a post to shed some more light on the issue.

DataContract types are uniquely identified using a namespace qualified name (namespace uri and a name). This namespace uri is used as the targetNamespace in XSD schemas created for that DataContract.

If a namespace uri is not specified when a DataContract is created, one is automatically created based on the CLR namespace of the type and using the prefix "http://schemas.datacontract.org/2004/07/". (If you do not place your types in a CLR namespace then just the prefix is used).

To keep generated code as clean as possible, the client code generator doesn't generate an explicit namespace declaration if it doesn't have to. The problem with this approach is that VB.NET projects can affect the namespace of types using a root namespace. In the abscence of an explicit namespace uri declaration, changing a types namespace will also change it's schema which will affect it's wire representation.

As Ali pointed out, using the /namespace option with svcutil will fix the issue because the types namespace no longer maps directly to the auto-generated namespace and the code generator will have to explicitly define the namespace uri. Another way to make sure this doesn't happen is to define a namespace uri explicitly on the server. This should also cause the client to generate an explicit namespace uri definition.

You can also work around this by not not using a root namespace in your poject.

Note: This issue does not apply to service contracts because the default namespace does not affect wire communications.

I got a copy of WinZip last week for my x64 box because I needed to unzip a gzip file. I later realized that since I'm running a 64-bit version of vista, the handy WinZip context menu shell extenstions won't work (unless I run a 32-instance of explorer.exe). This was a bummer because I like being able to right click on an archive and extract it. I know Windows has had built in support for this since XP but it requires me to click one more time than winzip does so it's not as quick. In any case, not having the optio nto use WinZip, I wanted to go back to using the built in windows handler for zip files since it works fine (except for that one extra click I have to do).

How do you restore the default .zip file association in Windowx XP or Vista? It wasn't as simple as right clicking and selecting "Open with.." which is what I tried for about 5 minutes. turns out you can restore it this way though:

cmd /c assoc .zip=CompressedFolder

Thanks goes to Ramesh Srinivasan for pointing out how to do this: http://windowsxp.mvps.org/zipfldr.htm

"To celebrate its first birthday on November 22, Xbox 360™ becomes the first and only gaming console to provide HD and standard-definition TV shows and movies direct to you."

http://www.xbox.com/en-US/live/marketplace/moviestv/default.htm

Renting movies from Blockbuster was nice.
Renting movies from Netflix was even better for my lazy but.
Renting movies without ever having to leave the couch is priceless...

The first product I worked on here at Microsoft has shipped.

http://www.netfx3.com/blogs/news_and_announcements/archive/2006/11/06/.NET-Framework-3.0-has-been-released_2100_.aspx

It's a great feeling.

More LINQ goodness here. I love it!

I get a lot of internal feedback that the svcutil options are confusing. svcutil.exe originally started out as a fairly simple tool and over the years working towards shipping it's evolved into a Swiss army knife. I figure even though I don't work on WCF anymore I should post a few brain dumps here to try and help folks out there understand things better.

/reference can have multiple meanings/behaviors depending on the what you're trying to do. A lot of thought was given to changing the parameter to make things clearer but adding yet another flag to svcutil seemed like it would be just as confusing.

In almost all modes, the /reference option can be used to help svcutil.exe locate assemblies that it might need to load. When passed an executable assembly, svcutil may also load the config file associated with that assembly (if one exists). If there are types referenced from config that are not in the GAC and svcutil needs to load and svcutil needs to load them, the assemblies may need to be provided via the /reference option.These types could be extensions, service behaviors, or service implementations in library dlls. I think of this /reference behavior as being similar to the csc.exe /lib option.

During client code generation, the /reference option can be used to avoid generating types that already exist on the client machine. svcutil will examine the assemblies passed to it for contract types (DataContract and ServiceContract but not MessageContract in v1). Whenever it encounters a type in metadata that it thinks is the same as an existing type it found it will reference the existing type instead of creating a new one. This can be useful if multiple services share the same DataContracts or implement the same ServiceContract. In this mode it's actually acting to provide svcutil with a list of existing contract types. I think of this /reference behavior as being somewhat similar to the csc.exe /reference option.

The /excludeType option complements the /reference option by allowing individual types to be excluded from  the collection svcutil loads. consider the following command line:

svcutil myServiceHost.exe /serviceName:myServiceName

Since the serviceName attribute is referring to the configuration name of the service, It's completely valid to have 2 services with the same configuration name (using the ConfigurationName property on the ServiceBehavior attribute. If this were the case, the excludeType option could be used to indicate which type should not be loaded thereby clearing up the ambiguity. Similarly, when reflecting over an assembly to generate a list of existing types, there could be 2 CLR types that represent (or seem to represent) the exact same DataContract. Again to resolve the ambiguity we can use the /excludeType option to prevent one of the types from being loaded.

/excludeType has one more use. Even without the /reference flag, the /exclude type can be used to prevent Service Contract types from being loaded. When exporting service contracts from an assembly like this:

svcutil myAssembly.dll

Ordinarily the command-line above would export all contracts in the service but the use of the /excludeType option can be used to limit the set of contracts that are exported.

I hope this explanation clears up the /reference flag a little bit. If there are any other svcutil pain points you want to me to blog about let me know.

I ran into an issue this summer while helping some interns port Terrarium to use .Net 3.0 and since I haven't seen many posts about it I thought I'd write one in hopes of helping anyone else who runs into this. I'll also nudge Michael Marucheck to write a bit more when he has time since he knows a whole lot more about this than I do.

When using Duplex Channels it's often the case that you want to receive callbacks on a separate thread. For example, If you're waiting on some notification message from the server and would like to use a ManualResetEvent to block on receiving this message you'll find that in the default configuration your callback method never gets called. Over simplified versions of the 2 contracts in question are shown below:

[ServiceContract(CallbackContract = typeof(CallbackContract))]
public interface ServiceContract
{
    [OperationContract(IsOneWay=true)]
    void Register();
}
public interface CallbackContract
{
    [OperationContract(IsOneWay=true)]
    void Notification();
}

Assuming the following server implementation of the Register method

public void Register()
{
    OperationContext.Current.GetCallbackChannel<ICallbackContract>().Notify();
}

Given these 2 contracts one might expect to be able to write a button click event-handler in a WinForms client like this:

public partial class Client : Form, ICallbackContract
{
    static ManualResetEvent mre = new ManualResetEvent(false);

    public Client(string[] args)
    {
        InitializeComponent();
    } 

    private void button1_Click(object sender, EventArgs e)
    {
        IServiceContract service = DuplexChannelFactory<IServiceContract>.CreateChannel(this, "callback");

        service.Register();

        /*
         *
         * Do some other stuff here
         *
         */

        mre.WaitOne();

        /*
         *
         * Work that cannot be done until we receive a 
         * notification from the server.
         *
         */
    }

    void ICallbackContract.Notification()
    {
        Client.mre.Set();
    }
}

Unfortunately, the code in the Notification method above will never get called on the client side. This is because the default threading behavior of WCF causes callbacks to all run in the same SynchronizationContext. Since there is another thread in that synchronization context blocked waiting for notification to get called you effectively have deadlock.

Solution: Disable the use of synchronization contexts on your callback by applying a CallbackBehavior attribute to your callback implementation.

[CallbackBehavior(UseSynchronizationContext = false)]

Applying the attribute above to the class implementing your callback will allow you to receive callbacks while in a wait or while some other thread is executing in the WinForms SynchronizationContext. 

An alternative is to use the Background worker when making calls to the service. This will run outside the WinForms Synchronization context and allow incoming calls to run without blocking. Either way, you will need to be careful about calling Winforms methods from your callback methods since they won't run on the  UI thread. I like the first approach a little better especially if you set things up in the Form's Load method.

I don't know a whole lot about the SynchronizationContext class. I learned a bit from a post on Matt Dotson's blog and Stephen Toub talks about it a bit in a .Net Matters article. Hopefully someone on the WCF team will blog about this in a bit more detail.

 

Update: When I *nudged* Michael, he pointed out that I should just put the code I needed running after the postback all in the callback method. for a lot of cases this is indeed a better option. If you don't absolutely have to (and you rarely do) don't put a Wait in the UI thread. It's ugly and results i na bad user experience.

In our particular case we should have popped up a progress dialog with a spinning icon or other whiz-bang thing-ama-jig and used the background thread to wait. that way we could add a cancel dialog as well. However this was a port of exisitng code and refactoring the application wasn't an option.

I have some news I probably should have blogged about earlier. I am no longer on the Connected Framework team here at Microsoft. I switched teams a little over a month ago. I'm now working on the Zune team. I probably won't be blogging much about Zune for a while so if you're curious I recommend reading either Zune Insider or Madison and Pine. For the time being this blog will probably stick to WCF related topics.

I've been waiting a long time for someone to come out with something like this.

After almost a year and a half of not posting to my web log, I'm going try and start up again. To start things out, I'll talk a bit about what I've been doing lately.
 
For the past 2 years or so I've been working on the Windows Communication Foundation (formerly code-named "Indigo"). Most of the stuff I work on has something to do with implementing Indigo's support for various metadata specifications (WSDL, WS-Metadata Exchange, WS-Policy etc.).
 
Hopefully (if I do my job right), most people won't have to know or care too much what any of those specifications are. Things will just work and for the most part tools like svcutil.exe will do the work for you.
 
Hopeful now that I've stuck my head out in the open again, people will let me know what kind of stuff they'd like to hear from me in this space. I'll try and make the majority of my posts here about Indigo and other closely related technologies although I may insert the occasional post or two about other technologies I'm passionate about. I don't intend to start posting on a daily basis but hopefully I'll be posting more than once every year.

This is an amazing article on the difference between WSS (Windows SharePoint Services ) and (SPS) SharePoint Portal Server and how it all works.

I've always been a huge fan of SharePoint but I have had a love hate relationship of sorts. I love the fact that there is so much in SharePoint that can be customized. the SharePoint UI alone has so many levels at which it can be customized. You could probably completely rewrite the SharePoint UI in ASP.NET and still derive value from the ability to leverage the existing SharePoint Content Databases and the List forms provided by CAML1. the hate part of the relationship comes from the fact that customizing the existing UI is so simple to start out and then “bam!”  you hit a brick wall as the learning curve gains an infinite gradient. And I'm not talking about it becoming harder as you go I'm talking full on second derivatives equals infinity at some point. This is further compounded by the lack of a really good Developer oriented SharePoint editor. FrontPage works great for people who want to customize the Site in a WYSIWYG manor

1: do not read this as an endorsement of CAML

P.S. I haven't posted in a long while because my life has been relatively uninteresting for the past few weeks.

Chris Anderson led me to this: http://www.microsoft.com/presspass/press/2004/feb04/02-23EnhancedInfoPathPR.asp 

I haven't got a chance to play with this yet but I recall talking with Eric just this past weekend about InfoPath  We talked about some of the features I felt were  missing from it. Looks like I'll soon find out whether my wishes have been granted.

http://www.microsoft.com/downloads/details.aspx?FamilyId=D5ADC839-73F4-4299-ABA0-E88C90B25144&displaylang=en

More Posts Next page »
 
Page view tracker