Welcome to Windows Communication Foundation (WCF)
Top Tasks :

WCF Team Bloggers

Monday, August 06, 2007 - Posts

  • Throttling in WCF

    When your server is hosted out on the “big bad internet”, you need a way to make sure that you don’t get flooded with client requests. In WCF, our services support throttling as a way of mitigating potential DoS (denial of service) attacks. These throttles can also help you smooth load on your server and [...] Read More...
  • Custom Namespaces

    If you've ever looked at a generated WSDL file, you may be wondering how all of the different parts of the service description are reassembled to form WSDL. Today's article is about the namespaces in the WSDL file. Here's an example service that provides a unique custom namespace to each of the most common parts of the service description. using System; using System.ServiceModel; using System.ServiceModel.Channels; using System.ServiceModel.Description; using System.Runtime.Serialization; [DataContract(Namespace = "http://example.com/faultcontract/datacontract" )] public class MyFault { [DataMember] public string detail; } [DataContract(Namespace = "http://example.com/datacontract" )] public class MyData { [DataMember] public string data; } [MessageContract(IsWrapped = true , WrapperNamespace = "http://example.com/messagecontract" )] public class MyMessage { [MessageHeader(Namespace = "http://example.com/messageheader" )] public string header; [MessageBodyMember(Namespace = "http://example.com/messagebodymember" )] public string member; } [ServiceContract(Namespace = "http://example.com/servicecontract" )] public interface IService { [FaultContract( typeof (MyFault), Namespace = "http://example.com/faultcontract/operationcontract" )] [OperationContract] void Operation1(MyData data); [OperationContract] void Operation2(MyMessage message); } [ServiceBehavior(Namespace= "http://example.com/servicebehavior" )] public class Service : IService { public void Operation1(MyData data) { } public void Operation2(MyMessage message) { } } class Program { static void Main( string [] args) { ServiceHost host = new ServiceHost( typeof (Service), new Uri( "http://localhost:8000/" )); Binding binding = new CustomBinding( new TextMessageEncodingBindingElement(), new HttpTransportBindingElement()); binding.Namespace = "http://example.com/binding" ; host.AddServiceEndpoint( typeof (IService), binding, "" ); host.Description.Behaviors.Add( new ServiceMetadataBehavior()); host.AddServiceEndpoint( typeof (IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex" ); host.Open(); Console.ReadLine(); host.Close(); } } You can run svcutil against this service to generate all of the WSDL and schema files. Now, we have a way to work backwards from the elements in the WSDL file to find where they are defined in the service description. Running svcutil gives me three WSDL files and seven schema files. One of the schema files covers the standard serialization types that are Read More...

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