Welcome to MSDN Blogs Sign in | Join | Help

WCF Instancing mode default is InstanceContextMode.PerSession

Keith Brown has been experimenting with InstanceContextMode.  This is the property on System.ServiceModel.ServiceBehaviorAttribute that determines how WCF handles instancing.  Keith correctly notes that the current documentation is wrong about the default value for this property.  The default value is not PerCall, but rather PerSession.  We changed this in the June CTP.  Here's the reasoning:

"With PerCall, users who required a session in their ServiceContract would get a session that lasted the duration of a single call unless they changed the InstanceContextMode to PerSession. 

With the new default of PerSession, users who require a session will get instance lifetime tied to session channel lifetime, as they expect.  Users who don't require a session in their contract will still get instance lifetime that looks like PerCall.  The benefit of this change is that users get the instance lifetime they expect once they set session requirements on the contract, without having to tweak the InstanceContextMode."

The docs have been updated on wcf.netfx3.com under the resources tab.

If you are building your service to be stateless, it shouldn't matter if the same instance is reused for the lifetime of a channel.  Explicitly setting InstanceContextMode to PerCall simply means we will create a new InstanceContext for each call instead of reusing the instance associated with the session.

Posted by edpinto | 0 Comments

Vista Beta 2 to Jun CTP Breaking Changes

The breaking changes for the June CTP have now been posted. Raw API changes are here. This is pretty significant because you won't see very many changes after these ones.

Here are the changes you are most likely to encounter when porting your apps

Base addresses are now supported in config for self-hosted services.

Before

<configuration>
  <appSettings>
    <add key="baseAddress"
             value="http://localhost:8000/ServiceModelSamples/service" />
  </appSettings>
  <system.serviceModel>
    <services>
      <service name="Microsoft.ServiceModel.Samples.CalculatorService">
        <endpoint address=""
                        binding="wsHttpBinding"
                        contract="Microsoft.ServiceModel.Samples.ICalculator" />
       </service>
    </services>
  </system.serviceModel>
</configuration>

//Code to create ServiceHost
Uri uri = new Uri(ConfigurationManager.AppSettings["baseAddress"]);
ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService), uri);


After

<configuration>
  <system.serviceModel>
    <services>
      <service name="Microsoft.ServiceModel.Samples.CalculatorService">
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000/ServiceModelSamples/service"/>
          </baseAddresses>
        </host>
        <endpoint address=""
                        binding="wsHttpBinding"
                        contract="Microsoft.ServiceModel.Samples.ICalculator" />
       </service>
    </services>
  </system.serviceModel>
</configuration>

//Code to create ServiceHost
ServiceHost serviceHost = new ServiceHost(typeof(CalculatorService));

Configuration of behaviors has changed:

Behaviors are now scoped by service or by endpoint under system.serviceModel/behaviors/serviceBehaviors and system.serviceModel/behaviors/endpointBehaviors respectively.  Further, the system.serviceModel/behaviors/behavior/@returnUnknownExceptionsAsFaults has been replaced with system.serviceModel/behaviors/serviceBehaviors/serviceDebug/@includeExceptionDetailInFaults.  This attribute controls whether exception detail is included in a fault that occurs when a service encounters an unhandled exception.

Before

<behaviors>
  <behavior name="MyServiceAndEndpointBehavior"
                  returnUnknownExceptionsAsFaults="false">
     <!-- behavior elements can implement IServiceBehavior or IEndpointBehavior-->
  </behavior>
</behaviors>


After

<behaviors>
    <serviceBehaviors>
        <behavior name="MyServiceBehavior">
            <serviceDebug includeExceptionDetailInFaults="false" />
            <!-- all behavior elements implement IServiceBehavior -->
        </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
        <behavior name="MyEndpointBehavior">
            <!-- all behavior elements implement IEndpointBehavior -->
        </behavior>
    </endpointBehaviors>
 </behaviors>

Metadata is now off by default so for a service to expose metadata, the ServiceMetadataBehavior must be configured on the service. When this behavior is present, you can publish metadata by configuring an endpoint to expose the IMetadataExchange contract.  The following configuration exposes a mex endpoint at http://localhost/servicemodelsamples/service.svc/mex and also enables wsdl requests over HTTP GET at http://localhost/servicemodelsamples/service.svc?wsdl.

<configuration>
  <system.serviceModel>
    <services>
      <service name="Microsoft.ServiceModel.Samples.CalculatorService"
                    behaviorConfiguration="CalculatorServiceBehavior">
        <endpoint address=""
                         binding="wsHttpBinding"
                         contract="Microsoft.ServiceModel.Samples.ICalculator" />
        <endpoint address="mex"
                        binding="mexHttpBinding"
                        contract="IMetadataExchange" />
      </service>
    </services>

    <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
    <behaviors>
      <serviceBehaviors>
        <behavior name="CalculatorServiceBehavior">
          <serviceMetadata httpGetEnabled="True"/>
          <serviceDebug includeExceptionDetailInFaults="False" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

For client code updates, you should rerun svcutil.
Feel free to contact me, or ask questions on the WCF forum.

 

Posted by edpinto | 0 Comments

Feb CTP to Vista Beta 2 Breaking Changes

Vista Beta 2 is here! There are relatively few changes from the Feb CTP because Vista Beta 2 was locked down shortly after the Feb CTP.  You can find the breaking changes list here and the detailed api change report here.
Posted by edpinto | 0 Comments

Feb CTP Cert Tools

The MakeCert.exe and CertMgr.exe tools that shipped with the February CTP SDK don't run on Windows XP SP2 and Windows Server 2003.  If you happen to have Visual Studio 2005 installed with the .NET Framework SDK option, you can copy these tools from %ProgramFiles%\Microsoft Visual Studio 8\SDK\v2.0\Bin to the Windows SDK bin directory at %ProgramFiles%\Microsoft SDKs\Windows\v1.0\Bin.  Alternatively, you can use the same tools from a previous SDK.
Posted by edpinto | 0 Comments

Breaking changes for the Feb CTP

The Feb CTP is now available! A number of changes have been made that break existing code. The details have been posted here on our community site.  Raw API change reports are available here for reference.

Here are some of the most popular things that you'll run into when you port your apps.

Service configuration has changed:

system.serviceModel/services/service/@type has changed to system.serviceModel/services/service/@name.

Before

<configuration>
  <system.serviceModel>
    <services>
      <service
        type="Microsoft.ServiceModel.Samples.CalculatorService">
        <endpoint
          address=""
          binding="wsHttpBinding"
          contract="Microsoft.ServiceModel.Samples.ICalculator" />
      </service>
    </services>
  </system.serviceModel>
</configuration>


After

<configuration>
  <system.serviceModel>
    <services>
      <service
        name="Microsoft.ServiceModel.Samples.CalculatorService">
        <endpoint
          address=""
          binding="wsHttpBinding"
          contract="Microsoft.ServiceModel.Samples.ICalculator" />
      </service>
    </services>
  </system.serviceModel>
</configuration>

Also note that names in config are now strictly treated as configuration strings and not necessarily as types.  When using the WCF programming model the configuration names should be the full type names.  Assembly qualified type names are no longer supported.

The format for the .svc files has changed:

Before

<%@Service language=c# Debug="true" class="Microsoft.ServiceModel.Samples.CalculatorService" %>


After

<%@ServiceHost language=c# Debug="true" Service="Microsoft.ServiceModel.Samples.CalculatorService" %>

Your best bet to update client code is to rerun svcutil.

Looking forward, we have most of the changes we know of to date completed, but we will continue to listen to customer feedback, and react to interop and security testing which could result in additional changes to the OM.

Feel free to contact me, or ask questions on the WCF forum.

 

Posted by edpinto | 10 Comments

WCF Beta 1 to Nov CTP Breaking Changes

My name is Ed Pinto.  I work on the team delivering the Windows Communication Foundation (WCF).  Part of my responsibility is to focus on the usability of WCF.  In an effort to make the transition to the Nov/05 CTP a little easier we've put together a list of breaking changes that describes changes you are most likely to run into when porting your app.  Feel free to contact me, or ask questions on the WCF forum.

Major changes

Beta1 Nov/05 CTP
Config
Binding Names changed: Dropped ‘Profile’ and made transport naming consistent
wsProfileBinding wsHttpBinding
wsProfileDualBinding wsDualHttpBinding
netProfileTcpBinding netTcpBinding
netProfileDualTcpBinding netTcpBinding
netProfileNamedPipeBinding netNamedPipeBinding
netProfileMsmqBinding netMsmqBinding
msmqIntegrationBinding msmqIntegrationBinding
basicProfileBinding basicHttpBinding
Several config names have been simplified
@serviceType on service type
@bindingSectionName on endpoint binding
@contractType on endpoint contract
@configurationName on binding name
@configurationName on behavior name
Object Model
Service changes
ServiceHost<T>() ServiceHost(typeof(T))
ServiceSite InstanceContext
[InstanceMode=InstanceMode.Singleton] [InstanceContextMode=
InstanceContextMode.Single]
[InstanceMode=InstanceMode.PrivateSession] [InstanceContextMode=
InstanceContextMode.PerSession]
[InstanceMode=InstanceMode.PerCall] [InstanceContextMode=
InstanceContextMode.PerCall]
[InstanceMode=InstanceMode.SharedSession] [InstanceContextMode=
InstanceContextMode.Shareable]
[OperationBehavior(AutoCompleteTransaction=
false]
[OperationBehavior(TransactionAutoComplete=
false]
[OperationBehavior(AutoEnlistTransaction=
false]
[OperationBehavior(TransactionScopeRequired=
false]
[BindingRequirements(
TransactionFlowRequirements=
RequirementsMode.Require)]
 [TransactionFlow(TransactionFlowOption.Required)]
On the operation
[BindingRequirements(
QueuedDeliveryRequirements=
RequirementsMode.Require)
[BindingRequirements(QueuedDeliveryRequirements=
BindingRequirementsMode.Required)
System.Runtime.Serialization.XmlFormatter is the default formatter. To use the XmlSerializer, apply the XmlSerializerFormat attribute
[ServiceContract(FormatMode=serializer)] [XmlSerializerFormat]
Client Changes
ProxyBase ClientBase<T>
IProxyChannel IClientChannel
Fault Changes
Fault<T> FaultException<T>
UnknownFault UnknownFaultException
DataContract
DataMember.IsOptional DataMember.IsRequired, default is false
Existing code that implements IBodyWriter will need to change to implement BodyWriter.OnWriteBodyContents instead of IBodyWriter.WriteBody
IBodyWriter BodyWriter
Binding Names changed: Dropped ‘Profile’ and made transport naming consistent
WsProfileBinding WSHttpBinding
WsProfileDualBinding WSDualHttpBinding
NetProfileTcpBinding NetTcpBinding
NetProfileDualTcpBinding NetTcpBinding
NetProfileNamedPipeBinding NetNamedPipeBinding
NetProfileMsmqBinding NetMsmqBinding
MsmqIntegrationBinding MsmqIntegrationBinding
BasicProfileBinding BasicHttpBinding

Changing Configuration:

  1. Replace <service serviceType="…"> with <service type="…">
  2. Replace <endpoint contractType="…" bindingSectionName= "…"> with <endpoint contract="…" binding="…">
  3. Replace <behavior configurationName="…"> with <behavior name="…">
  4. Replace <binding configurationName="…"> with <binding name="…">
  5. Replace the old binding names with the new ones. Refer to the table for the new binding names.

You no longer configure a uniquely named security element within a binding configuration. You set the security mode (usually one of Transport, Message, or TransportWithMessageCredential) using binding\security\@mode. Depending on the binding and the selected security mode, you configure the binding\security\message element or the binding\security\transport element.

In the same way, reliableSession is a standard element available under most bindings.

The following is a sample of new configuration:

<configuration>
    <
system.serviceModel
>

        <
services
>
            <
service

               
type="Microsoft.ServiceModel.Samples.CalculatorService"

               
behaviorConfiguration="CalculatorServiceBehavior">
                <!--
use base address provided by host
-->
                <
endpoint address=
""
                   
binding="wsHttpBinding
"
                   
bindingConfiguration="MessageSecurity
"
                   
contract="Microsoft.ServiceModel.Samples.ICalculator"
/>
            </
service
>
        </
services
>

        <
bindings
>
            <
wsHttpBinding
>
                <
binding name="MessageSecurity"
>
                    <
security mode="Message"
>
                        <
message clientCredentialType="Windows"
/>
                    </
security
>
                </
binding
>
            </
wsHttpBinding
>
        </
bindings
>

        <
behaviors
>
            <
behavior

               
name="CalculatorServiceBehavior"
>
                <
metadataPublishing enableHelpPage="false"
/>
            </
behavior
>
        </
behaviors
>

    </
system.serviceModel
>
</
configuration
>

Here is a sample client config:


<
configuration>
    <
system.serviceModel
>

        <
client
>
            <
endpoint address="
http://localhost/servicemodelsamples/service.svc"
                     
binding="wsHttpBinding"

                     
bindingConfiguration="MessageSecurity"

                     
contract="ICalculator"
/>
        </
client
>

        <
bindings
>
            <
wsHttpBinding
>
                <
binding name="MessageSecurity"
>
                    <
security mode="Message"
>
                        <
message clientCredentialType="Windows"
/>
                    </
security
>
                </
binding
>
            </
wsHttpBinding
>
        </
bindings
>

    </
system.serviceModel
>
</
configuration
>

For client code, your best bet is to rerun svcutil.

Namespaces

Removed
Microsoft.Tools.Indigo
Microsoft.Transactions.Bridge.Configuration
Microsoft.Transactions.Bridge.Dtc
Microsoft.Transactions.Wsat.Protocol
System.ServiceModel.Diagnostics
System.ServiceModel.QueueHelper
System.ServiceModel.QueueHelper.Design
System.Transactions.Isolation
System.Transactions.Recovery
Added
System.ServiceModel.Install.Configuration

Detail

Detailed API change reports are available here on Omri's blog.  They cover:

  • Beta1 to Nov/05 CTP
  • Beta 1 to PDC,
  • PDC to Nov/05 CTP

These reports are not intended for end to end consumption, but rather they offer a reference to help you decipher changes when you know the name of an API in the Beta1, the PDC, or the Nov/05 CTP build.

Update Dec 14, 2005:  Added link to detailed list.

Update Dec 20, 2005:  Corrected InstanceMode.Shared to be InstanceMode.Shareable

Posted by edpinto | 0 Comments
 
Page view tracker