Welcome to Windows Communication Foundation (WCF)
Top Tasks :

WCF Team Bloggers

Browse by Tags

All Tags » Indigo » Orcas   (RSS)

  • Getting Better Time Formats

    Orcas introduced a new DateTimeOffset class that is easier to use for representing absolute times than the original DateTime class. However, if you run svcutil on a contract that contains a DateTimeOffset, you'll get an ugly generated structure because DateTimeOffset isn’t recognized as a natively supported type by the system. A new class is generated by svcutil to match the schema for DateTimeOffset in the metadata. namespace System { using System.Runtime.Serialization; [DebuggerStepThroughAttribute()] [GeneratedCodeAttribute( "System.Runtime.Serialization" , "3.0.0.0" )] [DataContractAttribute(Name= "DateTimeOffset" , Namespace= "http://schemas.datacontract.org/2004/07/System" )] public partial struct DateTimeOffset : IExtensibleDataObject { private ExtensionDataObject extensionDataField; private DateTime DateTimeField; private short OffsetMinutesField; public ExtensionDataObject ExtensionData { get { return this .extensionDataField; } set { this .extensionDataField = value ; } } [DataMemberAttribute(IsRequired= true )] public DateTime DateTime { get { return this .DateTimeField; } set { this .DateTimeField = value ; } } [DataMemberAttribute(IsRequired= true )] public short OffsetMinutes { get { return this .OffsetMinutesField; } set { this .OffsetMinutesField = value ; } } } } There's a new option on svcutil, /targetClientVersion:Version35, that can be used to indicate that code generation should use new features in Orcas. As far as I know, there are three places where this option makes a difference. DateTimeOffset is automatically added as a known type when referenced Asynchronous methods are generated using the Orcas event-based asynchronous model Additional LINQ types are supported during schema import for XmlSerializer Next time: Read Only Data Members Read More...
  • Silverlight-Java Interoperability

    Robert Bell wrote an article a few weeks ago discussing how to achieve interoperability between a Silverlight application and a Java application . In the article Robert covers interoperability when building SOAP services, REST services, and RSS services. Note that this description is targeted at the Beta 2 release of Silverlight 2, so there may be a few more features and tricks at your disposal in the final release. Read More...
  • Streaming Web Content

    How do I deliver content from a WCF service as part of a web page? Web page content in this case typically refers to HTML, images, or other data that is directly consumed by the web browser rather than an application running in the web browser. There are a few things you need to do to make your web service serve up content in a way that's indistinguishable from an ordinary web server. I'll serve up a static image at a fixed location for this example but you can get as fancy as you'd like. The first thing you need is the right contract. The initial page load is ordinarily retrieved using the HTTP GET verb rather than the HTTP POST verb assumed by web services. I'll set that up as part of my contract using the WebGet attribute to set the verb and a URI template to set the address. [ServiceContract] public interface IService { [OperationContract] [WebGet(UriTemplate = "/image" )] Stream GetImage(); } The second thing you need is the right content type. Although web browsers can try to autodetect content, you should specify the content type if it is known. This allows the web browser to process the content correctly inline. public class Service : IService { public Stream GetImage() { WebOperationContext.Current.OutgoingResponse.ContentType = "image/jpeg" ; return new FileStream( "c:\\test.jpg" , FileMode.Open, FileAccess.Read); } } Finally, you may notice that while I've done everything needed in the service implementation to enable streaming, content can only be streamed if the binding supports this as well. When using WebServiceHost, the default bindings do not support streamed content. This may be hard to spot because the typical files are small and a test program running on the same machine completes the transfers before streaming would make a difference. I've wrapped the service implementation in this example to intentionally slow down the transfer to make the difference more apparent. The following code demonstrates enabling streaming on the binding. You can change the transfer mode back to Buffered to observe the difference. Streaming requires support in the receiving application as well to make a difference. Using a large, progressive encoded image will demonstrate this. using System; using System.IO; using System.ServiceModel; using System.ServiceModel.Web; using System.Threading; public class SlowStream : Stream { Stream innerStream; public SlowStream(Stream innerStream) { this .innerStream = innerStream; } public override bool CanRead { get { return Read More...
  • Orcas Screencasts

    One last bit of Orcas news for this week. PluralSight will be providing a weekly screencast throughout the year on using WF and WCF. They're focusing on the capabilities of Orcas but will be starting from the basics so you don't need to have any background going into these. The first screencast is by Aaron Skonnard and covers contracts and creating services. Creating Your First WCF Service Read More...
  • Orcas SP1 Released

    The first service pack for .NET Framework 3.5 came out yesterday, primarily focusing on fixing bugs and performance issues. There are some new features, notably around improving the support for REST based services and around serialization. Microsoft .NET Framework 3.5 Service Pack 1 Microsoft .NET Framework 3.5 Service Pack 1 (SP1) Readme Microsoft Visual Studio 2008 Service Pack 1 Visual Studio 2008 Team Foundation Server Service Pack 1 Here are some known issues related to WCF in this release. Authentication failure when Windows authentication is used over certain transports WCF now specifies a default domain target name in Windows authentication scenarios. When upgrading, the client may see an authentication failure when the following conditions exist: The scenario uses ClientCredentialType.Windows, which specifies the Negotiate authentication scheme. The scenario uses http, https, or net.tcp. The service runs under a non-domain account. An example of the authentication failure is "System.ComponentModel.Win32Exception The target principal name is incorrect" To resolve this issue: The client must override the default domain target name by specifying the Service Principal Name of the server in the SpnEndpointIdentity class, or User Principal Name in the UpnEndpointIdentity class, and then passing the identity to the EndpointAddress. If the client uses Https and requires X509CertificateEndpointIdentity, the client must still specify the SpnEndpointIdentity or UpnEndpointIdentity. The X509CertificateEndpointIdentity enables validation of thumbprints. The client can work around the loss of validation by registering for the System.Net.ServicePointManager.ServerCertificateValidationCallback and performing thumbprint validation manually. Breaking changes in the SspiNegotiatedOverTransport authentication mode When WSHttpBinding, WS2007HttpBinding, or NetTcpBinding is used with SecurityMode = TransportWithMessageCredential and a client credential type of Windows, clients that previously authenticated to a service by using NTLM will now fail to authenticate, with the following error: "System.ComponentModel.Win32Exception: Security Support Provider Interface (SSPI) authentication failed. The server may not be running in an account with identity 'host/<hostname>'. If the server is running in a service account (Network Service for example), specify the account's ServicePrincipalName as the identity in the EndpointAddress for the server. If the server is running Read More...
  • StockTrader 2.0 Sample

    The .NET StockTrader was an end-to-end sample application released last year to demonstrate WCF and web service programming. A new version of StockTrader has been released to update the application with some of the new features in Orcas and Windows Server 2008. You can get StockTrader from MSDN. StockTrader 2.01 StockTrader 2.0 Overview StockTrader Configuration Service Overview Read More...
  • Avoiding Address Filters

    The address filter mode that we looked at last time solved the problem of funneling all of the messages with a given prefix address to our service instance. Changing the filter mode still left us with the problem of dispatching from that universal contract to all of the logical operations that live inside the address space. This is exactly the problem that UriTemplate solves. By combining templates and WebServiceHost, both of the problems get taken care of for us. Here is an equivalent contract and service implementation with some more semantics filled in for a particular application. All I've done is pick out part of the address space that I want to assign some implementation to. [ServiceContract] public interface IService2 { [OperationContract] [WebGet(UriTemplate = "/resource/{index}" )] string Get( string index); [OperationContract] [WebInvoke(UriTemplate = "/resource" )] void Add( string value ); } public class Service2 : IService2 { public string Get( string index) { Console.WriteLine( "Get {0} {1}" , WebOperationContext.Current.IncomingRequest.Method, OperationContext.Current.IncomingMessageHeaders.To); return null ; } public void Add( string value ) { Console.WriteLine( "Add {0} {1}" , WebOperationContext.Current.IncomingRequest.Method, OperationContext.Current.IncomingMessageHeaders.To); } } Hosting this service is basically the same. I can take out the endpoint definition because that gets inferred automatically. WebServiceHost host = new WebServiceHost( typeof (Service2), new Uri( "http://localhost:8000/" )); host.Open(); Client(); Console.ReadLine(); host.Close(); Finally, I can use the exact same client code as last time even though in the service I've changed my way of writing the service from a centralized approach to an address-based approach. ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>( new WebHttpBinding()); factory.Open(); IRequestChannel proxy = factory.CreateChannel( new EndpointAddress( "http://localhost:8000/" )); using ( new OperationContextScope((IContextChannel)proxy)) { Message request = Message.CreateMessage(MessageVersion.None, string .Empty, "data" ); request.Headers.To = new Uri( "http://localhost:8000/resource" ); WebOperationContext.Current.OutgoingRequest.Method = "POST" ; proxy.Request(request); } using ( new OperationContextScope((IContextChannel)proxy)) { Message request = Message.CreateMessage(MessageVersion.None, string .Empty); request.Headers.To = new Uri( "http://localhost:8000/resource/1" Read More...
  • Web Address Filters

    Here is a basic service that defines a universal contract to program against for building a simple HTTP application. The service doesn't do anything, but you can ignore that in this example. [ServiceContract] public interface IService { [OperationContract(Action = "*" , ReplyAction = "*" )] Message Request(Message msg); } public class Service : IService { public Message Request(Message msg) { Console.WriteLine( "{0} {1}" , WebOperationContext.Current.IncomingRequest.Method, msg.Headers.To); return null ; } } You might expect to run this service in a straightforward hosting environment. ServiceHost host = new ServiceHost( typeof (Service), new Uri( "http://localhost:8000/" )); host.AddServiceEndpoint( typeof (IService), new WebHttpBinding(), "" ); host.Open(); Console.ReadLine(); host.Close(); And, talk to it with the ordinarily convoluted client programming model. ChannelFactory<IRequestChannel> factory = new ChannelFactory<IRequestChannel>( new WebHttpBinding()); factory.Open(); IRequestChannel proxy = factory.CreateChannel( new EndpointAddress( "http://localhost:8000/" )); using ( new OperationContextScope((IContextChannel)proxy)) { Message request = Message.CreateMessage(MessageVersion.None, string .Empty, "data" ); request.Headers.To = new Uri( "http://localhost:8000/resource" ); WebOperationContext.Current.OutgoingRequest.Method = "POST" ; proxy.Request(request); } using ( new OperationContextScope((IContextChannel)proxy)) { Message request = Message.CreateMessage(MessageVersion.None, string .Empty); request.Headers.To = new Uri( "http://localhost:8000/resource/1" ); WebOperationContext.Current.OutgoingRequest.Method = "GET" ; WebOperationContext.Current.OutgoingRequest.SuppressEntityBody = true ; proxy.Request(request); } However, when you put these pieces together, it fails to work. The client turns out to be fine but there's a problem in the way that the service is hosted. More accurately, there's a problem with the interaction between the way the service is hosted and the way it's defined. By specifying an address for hosting the application, we're claiming all of the messages that go to that address. We're also claiming all of the messages that go to suffixes of that address as long as someone else hasn't claimed them first. Unfortunately, the endpoint doesn't know what to do with these extra messages. It just ignores them. What we want is for the endpoint to just take everything and let the service implementation decide what the addresses Read More...
  • Standards Guide

    Looking for a guide to all of the web services protocols implemented by WCF? There's no single document that captures all of the information, but there is a group of documents that talk about the implemented protocols and some of the choices in those implementations. The level of detail varies from document to document as a few are high-level summaries across areas of the product while others are low-level details of a particular protocol. Web Services Protocols Interoperability Guide Web Services Protocols Supported by System-Provided Interoperability Bindings Messaging Protocols Data Contract Schema Reference WSDL and Policy Security Protocols version 1.0 Security Protocols Reliable Messaging Protocol version 1.0 Reliable Messaging Protocol version 1.1 Transaction Protocols version 1.0 Transaction Protocols Context Exchange Protocol Mixing Trust Protocols in Federated Scenarios Next time: Help with Security Programming Read More...
  • Adding Headers to a Call (HTTP Version)

    Yesterday I talked about adding SOAP headers to an outgoing request using a variety of different methods. The most straightforward method was to create an OperationContextScope in your application code to establish an OutgoingMessageHeaders collection. Although HTTP headers are similar in spirit to SOAP headers, manipulating an HTTP header through code looks a bit different. SOAP headers are elevated to a special significance in the programming model. Everything else, including HTTP headers, is relegated to a general-purpose but distinctly second-class collection of message properties. On the OperationContextScope you'll find a parallel OutgoingMessageProperties collection that can be used for HTTP headers. In Orcas, the plain OperationContext also works as a WebOperationContext that gives the same first-class programming model to HTTP headers as you get with SOAP headers. Here's a comparison of the two approaches. using ( new OperationContextScope((IClientChannel)proxy)) { HttpRequestMessageProperty requestProperty = new HttpRequestMessageProperty(); requestProperty.Headers[ "X-header" ] = "value1" ; OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestProperty; proxy.Operation(); } using ( new OperationContextScope((IClientChannel)proxy)) { WebOperationContext.Current.OutgoingRequest.Headers[ "X-header" ] = "value2" ; proxy.Operation(); } Next time: Configuring SSL Host Headers Read More...
  • Web Service Webcasts in July

    Four more webcasts are coming this month to talk about some of the new web service features in Orcas. Each webcast is aimed at developers and lasts 60-90 minutes. Transactional Windows Communication Foundation Services with Juval Lowy (Level 200) Monday, July 07, 2008 10:00 AM Pacific Time Transactions are the key to building robust, high quality service-oriented applications. Windows Communication Foundation (WCF) provides a simple, declarative transaction support for service developers, enabling you to configure parameters such as enlistment and voting, all outside the scope of your service. In addition, WCF allows client applications to create transactions and to propagate transactions across service boundaries over a variety of transports. In this webcast, we explain how to configure transaction flow at the binding, contract, and service level, local versus distributed transactions, setting of service transactions, declarative voting, and the available configurations that best fit various application scenarios. Using Windows Workflow Foundation to Build Services with Jon Flanders (Level 300) Wednesday, July 09, 2008 10:00 AM Pacific Time Windows Workflow Foundation (WF) is a programming model, set of tools, and runtime environment which allows you to write declarative and reactive programs for Windows operating systems. WF is part of the Microsoft .NET Runtime, and it first appeared in Microsoft .NET 3.0. Windows Communication Foundation (WCF) is also a programming model, set of tools, and a runtime that first appeared in .NET 3.0. WCF is a framework for building applications that can communicate with each other over varied network protocols. In .NET 3.5, these programming models came closer together to allow easy integration, including allowing WF instances to use WCF to communicate to remote endpoints and allowing WF instances to become the service implementation for WCF endpoints. This is accomplished by two new Activities: ReceiveActivity and SendActivity as well as a new hosting infrastructure for service endpoints. In this webcast, we look at both sides of this integration to give you an overview of how to build WF/WCF applications. WCF Extensibility Deep Dive with Jesus Rodriguez (Level 400) Friday, July 11, 2008 10:00 AM Pacific Time Windows Communication Foundation (WCF) provides a rich messaging framework that extends beyond its capabilities for modeling and implementing services. One of the aspects where WCF really shines when compared with competitive Read More...
  • JSON Service Speed

    I've been playing with the DataContractJsonSerializer that comes with Orcas recently to produce some JSON-based services. DataContractJsonSerializer works just like any other XmlObjectSerializer, except of course that the serialization output looks nothing like XML when written out. {"content1":"this is content","content2":"this is more content","version":1} If you attempt to push the serialized output through an XML reader or writer and examine it though, that works too through some simple but seemingly magical transformations that happen behind the scenes. < root type ="object" > < content1 > this is content </ content1 > < content2 > this is more content </ content2 > < version type ="number" > 1 </ version > </ root > This transformation trick is one that we've used elsewhere as well to give the appearance of a consistent and highly-structured set of data formats while not actually incurring the costs of that structure. That led me to start trying to observe when the simpler structure of JSON actually provides a performance advantage over the standard DataContractSerializer. I've found that while JSON wins in terms of size, it doesn't always win in terms of serialization speed. Here were the observations that I made. DataContractJsonSerializer tended to be faster for small and simple workloads. When the number of types was small and the types didn't have very many members, DataContractJsonSerializer could beat DataContractSerializer by 25%. This was most often true when the bulk of the object data was string content. On the other hand, DataContractSerializer caught up and then started winning as the types got more complicated. I also noticed that there were some primitive types, such as floating-point numbers, where DataContractSerializer always had a significant advantage. DataContractSerializer could turn a 25% loss into a 25% win just by changing several of the fields of a small type to doubles. This shows that performance is a very hard thing to predict without taking measurements. I would have expected DataContractJsonSerializer to consistently win given the simpler and smaller output format but I was able to find several data contracts taken from popular services for which that wasn't true. Next time: Timeout Error Messages Read More...
  • How WebServiceHost Works

    WebServiceHost is a new feature in Orcas that makes it easy to put up simple web services that are built on HTTP and POX. However, there's no requirement that forces you to build REST and POX services using WebServiceHost. WebServiceHost exists to make a simple case easy, but you're not locked into using that approach if the simple case doesn't apply to you. Here's everything behind WebServiceHost if you want to build your own. WebServiceHostFactory exists to bootstrap WebServiceHost when building a web site in IIS WebServiceHost disables any service metadata or help pages so that they don't steal any part of the URI space under your web site WebServiceHost generates endpoints for all of your contract types with a WebHttpBinding so that you don't have to describe the service endpoints in a configuration file WebServiceHost adds a WebHttpBehavior to all of your service endpoints so that Get and Invoke operations in your service contract work without any additional setup Next time: Security Session Inactivity Read More...
  • Serializing XML to XML

    How should I represent raw XML content in a contract? It seems like it would be really easy to have within the large blob of XML that makes up a message, a small blob of XML. However, it's more challenging to deal with that situation than you might expect because that small blob of XML has to be handled unlike everything else. With most contracts you can chew along the message and place each of the resulting bits in its proper place. When trying to preserve the raw XML though, you have to know when not to chew. In your contract you should use XMLSerializer formatted fields to turn off most of the unnecessary thinking regarding the XML content. Then, XmlSerializer knows about special handling for XmlElement and XmlAttribute to complete the mapping between pieces in the message and fields in your type. These two types work under the covers with XmlSerializer even though they don't implement the standard contract for serialization. With Orcas, you can also use the new XElement type that is defined by XLinq. XLinq doesn't have any deep integration with XmlSerializer but XElement directly implements the IXmlSerializable contract to make things work. Next time: Mapping Client Certificates Read More...
  • Web Service Webcasts in June

    Five webcasts are coming this month to talk about some of the new web service features in Orcas. Each webcast is aimed at developers and lasts 60-90 minutes. Beyond the Endpoints with Windows Communication Foundation with Juval Lowy (Level 100) Wednesday, June 18, 2008 10:00 A.M.-11:30 A.M. Pacific Time Windows Communication Foundation (WCF) is more than just the next-generation platform for building connected systems. In many respects, WCF is the next development platform for Windows-based applications, providing system features that are presently crafted by hand on top of the Microsoft .NET Framework and the Windows operating system. In this webcast, we describe the power and productivity of WCF and demonstrate how it is a "better .NET Framework." We focus on the key system features of WCF so you can make educated decisions on aligning your product road map with WCF and assess the advantages of using WCF. We begin the webcast with a brief overview of WCF and the WCF architecture, and then we demonstrate data contract tolerance, instance management, transaction propagation, automatic synchronization, queued calls, and automatic security. geekSpeak: Workflow Services in .NET 3.5 with Jon Flanders (Level 200) Wednesday, June 18, 2008 12:00 P.M.-1:00 P.M. Pacific Time Windows Communication Foundation (WCF) and Windows Workflow Foundation (WF) are powerful technologies that were first introduced in the Microsoft .NET Framework 3.0. In release 3.5 of the .NET Framework, these two technologies work even better together. In this installment of geekSpeak, Jon Flanders from Pluralsight introduces you to workflow services , and he describes how workflow services unites WCF and WF and provides great new features for building solutions. Your hosts for this geekSpeak are Lynn Langit and Glen Gordon. Calling Services from Silverlight 2.0 with Jon Flanders (Level 300) Monday, June 23, 2008 9:00 A.M.-10:00 A.M. Pacific Time Microsoft Silverlight 2.0 browser plug-in provides an environment for building rich Internet applications (RIAs). Traditionally, these types of applications relied heavily on services such as Asynchronous JavaScript and XML (AJAX) for their functionality. In this webcast, we look at the facilities built into Silverlight 2.0 for calling services, and we discuss the options for implementing these services. Windows Communication Foundation and Windows Workflow Foundation Integration in Depth with Jesus Rodriguez (Level 400) Wednesday, June 25, 2008 10:00 Read More...
More Posts Next page »

Copyright © 2006 Microsoft Corporation. All Rights Reserved. | Terms of Use | Privacy Statement | Contact Us