Udostępnij za pośrednictwem


WCF February CTP: Tids and Bits. Post 2 -- Svcutil and Client ProtectionLevels

Here's a change that can be meaningful but is not in the Feb CTP breaking change list published here. Many if not most of my samples use the WSHttpBinding as the default binding in previous releases of WCF. If I did not use MessageContractAttribute and its confederates to specify the exact message structures, when I used svcutil to import proxy code I ended up with a service contract that looked much like my service contract, most particularly it would have typed parameters that were not decorated by the quite dictatorial MCA. This made nice friendly proxies for a client. So, if I had a service contract like the following:

[ServiceContract]
public interface IMyService
{
  [OperationContract]
  string Hello();
}

Then my client could use a ChannelFactory with a very similar if not identical contract to create a proxy or the MyServiceProxy class with a Hello method that returned a string.

No longer -- sort of. By default, the WSHttpBinding now insists upon encrypting and signing all messages unless you explicitly inform WCF not to do so. This is a Good Thing(TM). And because the only way to tell the client WCF application that messages are encrypted and signed is to use the MessageContractAttribute.ProtectionLevel property, suddenly svcutil falls into typed-message mode for all WSHttpBinding contracts by default. If you want your client to still use the nice, easy, typed parameter model with the proxy you still can do so -- svcutil generates a nice typed parameter version of the proxy method that your basic client can call. If you don't believe me, go look. :-)

BUT -- and for some this is a big but -- the IMyService service contract is now a strongly typed message contract. This means that if you were programming against the simple IMyService.Hello and expecting a string, you will now use ChannelFactory to create an IMyService with a Hello method that returns a HelloReply message which you must know how to unbundle to retrieve that string value.

If you had gotten very comfortable with the previous client contract interfaces and proxies appeared, this can be annoying. Remember that the proxy is still a fun, happy proxy just brimming with easy use. Of course, because the WS-I Basic Profile 1.1 specification does not support message-level encryption or signing, you can use the basicHttpBinding and get back all your previous behavior. Just don't think turning message-level security off will change the default behavior of WSHttpBinding; it won't. Because svcutil now must use the MCA.ProtectionLevel property to inform WCF to not encrypt and sign the message. So you get typed message contracts on the client anyway. :-)

Comments

  • Anonymous
    February 26, 2006
    Маджаяр расказывает об изменениях в модели расширений, Ральф Сквилэйс — о конфиг