Exemplo n.º 1
0
        /// <summary>
        /// Sets the request header namespace in outgoing Soap Requests.
        /// </summary>
        /// <param name="signature">The service creation parameters.</param>
        /// <param name="service">The service object for which RequestHeader
        /// needs to be patched.</param>
        private static void SetRequestHeaderNameSpace(DfaServiceSignature signature,
                                                      AdsClient service)
        {
            // Set the header namespace prefix. For all /cm services, the members
            // shouldn't have xmlns. For all other services, the members should have
            // /cm as xmlns.
            object[] attributes = service.GetType().GetCustomAttributes(false);
            foreach (object attribute in attributes)
            {
                if (attribute is WebServiceBindingAttribute)
                {
                    WebServiceBindingAttribute binding = (WebServiceBindingAttribute)attribute;

                    string        xmlns            = binding.Namespace;
                    RequestHeader svcRequestHeader = null;
                    PropertyInfo  propInfo         = service.GetType().GetProperty("RequestHeader");
                    if (propInfo != null)
                    {
                        svcRequestHeader = (RequestHeader)propInfo.GetValue(service, null);

                        if (svcRequestHeader != null)
                        {
                            PropertyInfo wsPropInfo = svcRequestHeader.GetType().GetProperty("TargetNamespace");
                            if (wsPropInfo != null)
                            {
                                wsPropInfo.SetValue(svcRequestHeader, xmlns, null);
                            }
                        }
                    }
                }
            }
        }