Ejemplo n.º 1
0
        internal static void Hook(ContractDescription contractDescription, ServiceEndpoint endpoint, ClientRuntime clientRuntime)
        {
            //Create a mapping between an operation and it's relevant headers
            Dictionary <string, OperationHeaders> headersFromAction = new Dictionary <string, OperationHeaders>();
            Dictionary <Type, SoapHeaderHelper>   soapHelpers       = new Dictionary <Type, SoapHeaderHelper>();

            foreach (OperationDescription op in contractDescription.Operations)
            {
                SoapHeaderAttribute[] soapHeaders = (SoapHeaderAttribute[])op.SyncMethod.GetCustomAttributes(typeof(SoapHeaderAttribute), false);
                if (soapHeaders.Length > 0)
                {
                    OperationHeaders headers = new OperationHeaders();
                    string           action  = contractDescription.Namespace + "/" + contractDescription.Name + "/" + op.Name;
                    foreach (SoapHeaderAttribute soapHeader in soapHeaders)
                    {
                        //prepare a cache of which headers needed in which Action
                        if ((soapHeader.Direction & SoapHeaderDirection.In) == SoapHeaderDirection.In)
                        {
                            headers.In.Add(soapHeader);
                        }
                        if ((soapHeader.Direction & SoapHeaderDirection.Out) == SoapHeaderDirection.Out)
                        {
                            headers.Out.Add(soapHeader);
                        }

                        //prepare a cache of SoapHeaderHelpers for each header type
                        if (!soapHelpers.ContainsKey(soapHeader.Type))
                        {
                            soapHelpers.Add(soapHeader.Type, new SoapHeaderHelper(soapHeader.Type));
                        }
                    }
                    headersFromAction.Add(action, headers);
                }
            }

            SoapHeadersClientHook clientHook = new SoapHeadersClientHook(headersFromAction, soapHelpers);

            clientRuntime.MessageInspectors.Add(clientHook);
            clientRuntime.ChannelInitializers.Add(clientHook);
        }
Ejemplo n.º 2
0
 void IContractBehavior.ApplyClientBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.ClientRuntime clientRuntime)
 {
     SoapHeadersClientHook.Hook(contractDescription, endpoint, clientRuntime);
 }