DevForce Help Reference
ServiceProxyEvents Class
Members  Example 


Provides a means of customizing a WCF proxy used to communicate with the BOS.
Syntax
'Declaration
 
<DefaultExportAttribute(IsDefault=True, 
   ContractName="", 
   ContractType=IdeaBlade.EntityModel.ServiceProxyEvents)>
Public Class ServiceProxyEvents 
'Usage
 
Dim instance As ServiceProxyEvents
[DefaultExport(IsDefault=true, 
   ContractName="", 
   ContractType=IdeaBlade.EntityModel.ServiceProxyEvents)]
public class ServiceProxyEvents 
Remarks
Communication with the WCF services comprising the BOS, the EntityService and all EntityServers, can be customized by sub-typing this class and overriding the methods provided.
Example
using System;
using System.ComponentModel.Composition;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using IdeaBlade.EntityModel;

  public class MyServiceProxyEvents : ServiceProxyEvents {

    // Called after an endpoint is created.
     public override void OnEndpointCreated(ServiceEndpoint endpoint) {

       // Here we'll tweak the binding to add security. 
       // Bindings used in DevForce are by default the CustomBinding type.
       // Remember that bindings on both the client and server must correspond
       // for communications to take place.  

       if (endpoint.Binding is CustomBinding) {

         var binding = endpoint.Binding as CustomBinding;
         var elements = binding.CreateBindingElements();

         // Add transport security.
         var transport = elements.Find<TransportBindingElement>();
         if (transport.Scheme != "https") {
           elements.Remove(transport);
           transport = new HttpsTransportBindingElement();
           elements.Add(transport);
         }
         var sec = new TransportSecurityBindingElement();
         elements.Insert(1, sec);

         // Replace the binding on the endpoint.
         endpoint.Binding = new CustomBinding(elements);

         var uri = endpoint.Address.Uri;
         var newUri = uri.AbsoluteUri.Replace("http", "https");
         endpoint.Address = new System.ServiceModel.EndpointAddress(newUri);
       }

      // Let's change the default timeouts too.
      endpoint.Binding.ReceiveTimeout = new TimeSpan(0, 2, 0);
      endpoint.Binding.SendTimeout = new TimeSpan(0, 2, 0);
    }

    // Called before a channel is created and opened from the ChannelFactory.
     public override void OnFactoryCreated(System.ServiceModel.ChannelFactory factory) {
       factory.Credentials.UserName.UserName = "name";
       factory.Credentials.UserName.Password = "pwd";
     }
  }
Inheritance Hierarchy

System.Object
   IdeaBlade.EntityModel.ServiceProxyEvents

Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

ServiceProxyEvents Members
IdeaBlade.EntityModel Namespace

Send Feedback