Esempio n. 1
0
        public static void Snippetop_Inequality()
        {
            AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader("specialservice1", "http://localhost:8000/service", 1);
            AddressHeader addressHeader2 = AddressHeader.CreateAddressHeader("specialservice2", "http://localhost:8000/service", 2);

            AddressHeader[] addressHeaders = new AddressHeader[2] {
                addressHeader1, addressHeader2
            };
            AddressHeaderCollection headers = new AddressHeaderCollection(addressHeaders);

            //<Snippet22>
            EndpointIdentity endpointIdentity =
                EndpointIdentity.CreateUpnIdentity(WindowsIdentity.GetCurrent().Name);
            EndpointAddress endpointAddress1 = new EndpointAddress(
                new Uri
                    ("http://localhost:8003/servicemodelsamples/service/incode/identity1"),
                endpointIdentity, addressHeaders);
            EndpointAddress endpointAddress2 = new EndpointAddress(
                new Uri
                    ("http://localhost:8003/servicemodelsamples/service/incode/identity2"),
                endpointIdentity, addressHeaders);

            bool op_Inequality_val = (endpointAddress1 != endpointAddress2);
            //</Snippet22>
        }
Esempio n. 2
0
        public static void Snippet3()
        {
            // Get base address from app settings in configuration
            Uri baseAddress = new Uri(ConfigurationManager.AppSettings["baseAddress"]);

            // <Snippet3>
            //Create new address headers for special services and add them to an array
            AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader("specialservice1", "http://localhost:8000/service", 1);
            AddressHeader addressHeader2 = AddressHeader.CreateAddressHeader("specialservice2", "http://localhost:8000/service", 2);

            AddressHeader[] addressHeaders = new AddressHeader[2] {
                addressHeader1, addressHeader2
            };
            AddressHeaderCollection addressHeaderColl = new AddressHeaderCollection(addressHeaders);

            // <Snippet#15>
            EndpointIdentity endpointIdentity = EndpointIdentity.CreateUpnIdentity(WindowsIdentity.GetCurrent().Name);
            EndpointAddress  endpointAddress  = new EndpointAddress(
                new Uri("http://localhost:8003/servicemodelsamples/service/incode/identity"),
                endpointIdentity,
                addressHeaderColl);
            EndpointIdentity thisEndpointIdentity = endpointAddress.Identity;
            // </Snippet#15>

            // </Snippet3>
        }
Esempio n. 3
0
        private void Init(AddressingVersion version, Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlBuffer buffer, int metadataSection, int extensionSection, int pspSection)
        {
            if (!uri.IsAbsoluteUri)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument(nameof(uri), SR.UriMustBeAbsolute);
            }

            _addressingVersion = version;
            Uri               = uri;
            Identity          = identity;
            _headers          = headers;
            Buffer            = buffer;
            _metadataSection  = metadataSection;
            _extensionSection = extensionSection;
            _pspSection       = pspSection;

            if (version != null)
            {
                IsAnonymous = uri == version.AnonymousUri;
                IsNone      = uri == version.NoneUri;
            }
            else
            {
                IsAnonymous = ReferenceEquals(uri, AnonymousUri) || uri == AnonymousUri;
                IsNone      = ReferenceEquals(uri, NoneUri) || uri == NoneUri;
            }
            if (IsAnonymous)
            {
                Uri = AnonymousUri;
            }
            if (IsNone)
            {
                Uri = NoneUri;
            }
        }
Esempio n. 4
0
        public static void SnippetReadFrom2()
        {
            AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader("specialservice1", "http://localhost:8000/service", 1);
            AddressHeader addressHeader2 = AddressHeader.CreateAddressHeader("specialservice2", "http://localhost:8000/service", 2);

            AddressHeader[] addressHeaders = new AddressHeader[2] {
                addressHeader1, addressHeader2
            };
            AddressHeaderCollection headers = new AddressHeaderCollection(addressHeaders);

            EndpointAddress endpointAddress = new EndpointAddress(
                new Uri("http://localhost:8003/servicemodelsamples/service/incode/identity"), addressHeaders);

            XmlWriter           writer     = XmlWriter.Create("addressdata.xml");
            XmlDictionaryWriter dictWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer);

            endpointAddress.WriteTo(AddressingVersion.WSAddressing10, dictWriter);
            dictWriter.Close();

            // <Snippet25>
            XmlReader           reader     = XmlReader.Create("addressdata.xml");
            XmlDictionaryReader dictReader = XmlDictionaryReader.CreateDictionaryReader(reader);
            EndpointAddress     createdEA  = EndpointAddress.ReadFrom
                                                 (AddressingVersion.WSAddressing10,
                                                 dictReader);
            // </Snippet25>
        }
Esempio n. 5
0
        //public EndpointAddress(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers)
        //{
        //    if (uri == null)
        //    {
        //        throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(uri));
        //    }

        //    Init(uri, identity, headers, null, -1, -1, -1);
        //}

        internal EndpointAddress(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlDictionaryReader metadataReader, XmlDictionaryReader extensionReader, XmlDictionaryReader pspReader)
        {
            if (uri == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(uri));
            }

            XmlBuffer buffer = null;

            PossiblyPopulateBuffer(metadataReader, ref buffer, out metadataSection);

            EndpointIdentity ident2;
            int extSection;

            buffer = ReadExtensions(extensionReader, null, buffer, out ident2, out extSection);

            if (identity != null && ident2 != null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.MultipleIdentities, nameof(extensionReader)));
            }

            PossiblyPopulateBuffer(pspReader, ref buffer, out pspSection);

            if (buffer != null)
            {
                buffer.Close();
            }

            Init(uri, identity ?? ident2, headers, buffer, metadataSection, extSection, pspSection);
        }
Esempio n. 6
0
        public static void SnippetWriteToAddressingVersionXmlWriterXmlDictionaryStringXmlDictionaryString()
        {
            AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader("specialservice1", "http://localhost:8000/service", 1);
            AddressHeader addressHeader2 = AddressHeader.CreateAddressHeader("specialservice2", "http://localhost:8000/service", 2);

            AddressHeader[] addressHeaders = new AddressHeader[2] {
                addressHeader1, addressHeader2
            };
            AddressHeaderCollection headers = new AddressHeaderCollection(addressHeaders);

            EndpointAddress endpointAddress = new EndpointAddress(
                new Uri("http://localhost:8003/servicemodelsamples/service/incode/identity"), addressHeaders);

            // <Snippet33>
            XmlWriter           writer     = XmlWriter.Create("addressdata.xml");
            XmlDictionaryWriter dictWriter = XmlDictionaryWriter.CreateDictionaryWriter(writer);

            XmlDictionary       d           = new XmlDictionary();
            XmlDictionaryString xdLocalName = new XmlDictionaryString(XmlDictionary.Empty, "EndpointReference", 0);
            XmlDictionaryString xdNamespace = new XmlDictionaryString(XmlDictionary.Empty, "http://www.w3.org/2005/08/addressing", 0);

            endpointAddress.WriteTo(
                AddressingVersion.WSAddressing10,
                dictWriter,
                xdLocalName,
                xdNamespace);
            writer.Close();
            // </Snippet33>
        }
Esempio n. 7
0
        void Init(AddressingVersion version, Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlBuffer buffer, int metadataSection, int extensionSection, int pspSection)
        {
            if (!uri.IsAbsoluteUri)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("uri", SR.UriMustBeAbsolute);
            }

            addressingVersion     = version;
            this.uri              = uri;
            this.identity         = identity;
            this.headers          = headers;
            this.buffer           = buffer;
            this.metadataSection  = metadataSection;
            this.extensionSection = extensionSection;
            this.pspSection       = pspSection;

            if (version != null)
            {
                isAnonymous = uri == version.AnonymousUri;
                isNone      = uri == version.NoneUri;
            }
            else
            {
                isAnonymous = object.ReferenceEquals(uri, AnonymousUri) || uri == AnonymousUri;
                isNone      = object.ReferenceEquals(uri, NoneUri) || uri == NoneUri;
            }
            if (isAnonymous)
            {
                this.uri = AnonymousUri;
            }
            if (isNone)
            {
                this.uri = NoneUri;
            }
        }
Esempio n. 8
0
        public static void Snippet6()
        {
            AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader("specialservice1", "http://localhost:8000/service", 1);
            AddressHeader addressHeader2 = AddressHeader.CreateAddressHeader("specialservice2", "http://localhost:8000/service", 2);

            AddressHeader[] addressHeaders = new AddressHeader[2] {
                addressHeader1, addressHeader2
            };
            AddressHeaderCollection headers = new AddressHeaderCollection(addressHeaders);

            EndpointAddress endpointAddress = new EndpointAddress(
                new Uri("http://localhost:8003/servicemodelsamples/service/incode/identity"), addressHeaders);

            // <Snippet6>
            // <Snippet8>
            XmlDictionaryReader metadataReader = endpointAddress.GetReaderAtMetadata();
            // </Snippet8>
            // <Snippet7>
            XmlDictionaryReader extensionReader = endpointAddress.GetReaderAtExtensions();
            // </Snippet7>
            EndpointIdentity identity = EndpointIdentity.CreateUpnIdentity(WindowsIdentity.GetCurrent().Name);

            EndpointAddress endpointAddress2 = new EndpointAddress(
                new Uri("http://localhost:8003/servicemodelsamples/service/incode/identity"), identity, headers, metadataReader, extensionReader);
            // </Snippet6>
        }
Esempio n. 9
0
        private static bool GetRemoteEnlistmentId(EndpointAddress address, out Guid remoteEnlistmentId)
        {
            AddressHeaderCollection headers = address.Headers;

            if (headers.Count == 1)
            {
                AddressHeader header = headers.FindHeader("Enlistment", "http://schemas.microsoft.com/ws/2006/02/transactions");
                if (header != null)
                {
                    XmlDictionaryReader addressHeaderReader = header.GetAddressHeaderReader();
                    XmlDictionaryReader reader2             = addressHeaderReader;
                    try
                    {
                        ControlProtocol protocol;
                        EnlistmentHeader.ReadFrom(addressHeaderReader, out remoteEnlistmentId, out protocol);
                        return(protocol == ControlProtocol.Durable2PC);
                    }
                    catch (InvalidEnlistmentHeaderException exception)
                    {
                        Microsoft.Transactions.Bridge.DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Information);
                    }
                    finally
                    {
                        if (reader2 != null)
                        {
                            reader2.Dispose();
                        }
                    }
                }
            }
            remoteEnlistmentId = Guid.Empty;
            return(false);
        }
Esempio n. 10
0
 public EndpointAddress(System.Uri uri, EndpointIdentity identity, AddressHeaderCollection headers)
 {
     if (uri == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("uri");
     }
     this.Init(uri, identity, headers, null, -1, -1, -1);
 }
 public EndpointAddress(System.Uri uri, EndpointIdentity identity, AddressHeaderCollection headers)
 {
     if (uri == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("uri");
     }
     this.Init(uri, identity, headers, null, -1, -1, -1);
 }
Esempio n. 12
0
        private void DeserializeElementCore(XmlReader reader)
        {
#if DESKTOP
            this.Headers = AddressHeaderCollection.ReadServiceParameters(XmlDictionaryReader.CreateDictionaryReader(reader));
#else
            throw new PlatformNotSupportedException();
#endif
        }
        public static void WriteAddressHeaders(this AddressHeaderCollection col)
        {
            var headers = OperationContext.Current.OutgoingMessageHeaders;

            foreach (var header in col)
            {
                headers.Add(new AddressMessageHeader(header));
            }
        }
Esempio n. 14
0
        private static TService HttpsCreate <TService>(string url, int TimeOut)
        {
            Uri uri = new Uri(url);

            ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
            WSHttpBinding binding = new System.ServiceModel.WSHttpBinding();

            binding.SendTimeout    = new TimeSpan(0, TimeOut / 60, TimeOut % 60);
            binding.ReceiveTimeout = new TimeSpan(0, TimeOut / 60, TimeOut % 60);

            #region  设置一些配置信息
            binding.Security.Mode = SecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

            #endregion

            System.ServiceModel.Web.WebOperationContext ctx = System.ServiceModel.Web.WebOperationContext.Current;
            var token = ctx.IncomingRequest.Headers["token"].ToString();

            AddressHeaderCollection addressHeaderColl;
            if (!string.IsNullOrEmpty(token))
            {
                AddressHeader   addressHeader1 = AddressHeader.CreateAddressHeader("token", "", token);
                AddressHeader[] addressHeaders = new AddressHeader[] { addressHeader1 };
                addressHeaderColl = new AddressHeaderCollection(addressHeaders);
            }
            else
            {
                addressHeaderColl = new AddressHeaderCollection();
            }
            //
            //string[] cers = ZH.Security.Client.CertUtil.GetHostCertificate(uri);
            //TODO 证书处理
            string[] cers        = "".Split('.');
            var      IdentityDns = EndpointIdentity.CreateDnsIdentity(cers[0]);
            //
            System.ServiceModel.EndpointAddress endpoint = new EndpointAddress(uri, IdentityDns, addressHeaderColl);

            ChannelFactory <TService> channelfactory = new ChannelFactory <TService>(binding, endpoint);
            foreach (OperationDescription op in channelfactory.Endpoint.Contract.Operations)
            {
                DataContractSerializerOperationBehavior dataContractBehavior = op.Behaviors.Find <DataContractSerializerOperationBehavior>() as DataContractSerializerOperationBehavior;
                if (dataContractBehavior != null)
                {
                    dataContractBehavior.MaxItemsInObjectGraph = int.MaxValue;
                }
            }
            //
            channelfactory.Credentials.ServiceCertificate.DefaultCertificate = new X509Certificate2(Convert.FromBase64String(cers[1])); // new X509Certificate2(x509certificate);            \

            //
            //返回工厂创建
            TService tservice = channelfactory.CreateChannel();
            //
            return(tservice);
        }
Esempio n. 15
0
        public static void Main()
        {
            // <Snippet0>

            // <Snippet1>
            // Name property
            AddressHeader addressHeaderWithName = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service", 1);
            string        addressHeaderName     = addressHeaderWithName.Name;
            // </Snippet1>

            // <Snippet2>
            //Put snippet here.
            // Namespace property
            AddressHeader addressHeaderWithNS = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service", 1);
            string        addressHeaderNS     = addressHeaderWithNS.Namespace;
            // </Snippet2>

            // <Snippet3>
            // Obsolete
            // </Snippet3>

            // <Snippet4>
            // Obsolete
            // </Snippet4>

            // <Snippet5>
            // Create address headers for special services and add them to an array
            AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader("specialservice1", "http://localhost:8000/service", 1);
            AddressHeader addressHeader2 = AddressHeader.CreateAddressHeader("specialservice2", "http://localhost:8000/service", 2);

            AddressHeader[] addressHeaders = new AddressHeader[2] {
                addressHeader1, addressHeader2
            };

            // Endpoint address constructor with URI and address headers
            EndpointAddress endpointAddressWithHeaders = new EndpointAddress(
                new Uri("http://localhost/silverlightsamples/service1"), addressHeaders
                );

            // Confirm adddressHeader1 is in endpointAddressWithHeaders - boolHeaders returns True.
            AddressHeaderCollection addressHeaderCollection = endpointAddressWithHeaders.Headers;
            bool boolHeaders = addressHeaderCollection.Contains(addressHeader1);
            // </Snippet5>

            // <Snippet10>
            // <Snippet6>
            //Create address headers with XmlObjectSerializer specified
            XmlObjectSerializer serializer = new DataContractSerializer(typeof(int));
            AddressHeader       addressHeaderWithObjSer = AddressHeader.CreateAddressHeader("MyServiceName", "http://localhost:8000/service", 1, serializer);
            int value = addressHeaderWithObjSer.GetValue <int>();
            // </Snippet6>
            // </Snippet10>

            // </Snippet0>
        }
 internal EndpointInfo(ServiceEndpoint endpoint, string serviceName)
 {
     this.endpoint    = endpoint;
     this.address     = endpoint.Address.Uri;
     this.headers     = endpoint.Address.Headers;
     this.identity    = endpoint.Address.Identity;
     this.behaviors   = endpoint.Behaviors;
     this.serviceName = serviceName;
     this.binding     = (endpoint.Binding == null) ? new CustomBinding() : new CustomBinding(endpoint.Binding);
     this.contract    = endpoint.Contract;
 }
 internal EndpointInfo(ServiceEndpoint endpoint, string serviceName)
 {
     this.endpoint = endpoint;
     this.address = endpoint.Address.Uri;
     this.headers = endpoint.Address.Headers;
     this.identity = endpoint.Address.Identity;
     this.behaviors = endpoint.Behaviors;
     this.serviceName = serviceName;
     this.binding = (endpoint.Binding == null) ? new CustomBinding() : new CustomBinding(endpoint.Binding);
     this.contract = endpoint.Contract;
 }
Esempio n. 18
0
        internal EndpointInfo(ServiceEndpoint endpoint, string serviceName)
        {
            Fx.Assert(null != endpoint, "endpoint cannot be null");

            this.endpoint = endpoint;
            this.address = endpoint.Address.Uri;
            this.headers = endpoint.Address.Headers;
            this.identity = endpoint.Address.Identity;
            this.behaviors = endpoint.Behaviors;
            this.serviceName = serviceName;

            this.binding = null == endpoint.Binding ? new CustomBinding() : new CustomBinding(endpoint.Binding);
            this.contract = endpoint.Contract;
        }
Esempio n. 19
0
        internal EndpointInfo(ServiceEndpoint endpoint, string serviceName)
        {
            Fx.Assert(null != endpoint, "endpoint cannot be null");

            this.endpoint    = endpoint;
            this.address     = endpoint.Address.Uri;
            this.headers     = endpoint.Address.Headers;
            this.identity    = endpoint.Address.Identity;
            this.behaviors   = endpoint.Behaviors;
            this.serviceName = serviceName;

            this.binding  = null == endpoint.Binding ? new CustomBinding() : new CustomBinding(endpoint.Binding);
            this.contract = endpoint.Contract;
        }
Esempio n. 20
0
        private static T GetServiceByFactory <T>(String URL, string strUserName, string strPassword)
        {
            if (BCheckService(URL))
            {
                return((T)DicChannel[URL]);
            }
            ChannelFactory <T> factory = null;

            if (!BCheckFactory(URL))
            {
                AddressHeaderCollection ahc = new AddressHeaderCollection();
                EndpointAddress         EPD = new EndpointAddress(new Uri(URL), EndpointIdentity.CreateDnsIdentity(dnsName), ahc);
                WSHttpBinding           wh  = new WSHttpBinding(SecurityMode.None);

                //wh.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
                wh.MaxBufferPoolSize                   = 2147483647;
                wh.MaxReceivedMessageSize              = 2147483647;
                wh.ReaderQuotas.MaxArrayLength         = 2147483647;
                wh.ReaderQuotas.MaxBytesPerRead        = 2147483647;
                wh.ReaderQuotas.MaxDepth               = 2147483647;
                wh.ReaderQuotas.MaxNameTableCharCount  = 2147483647;
                wh.ReaderQuotas.MaxStringContentLength = 2147483647;
                wh.ReceiveTimeout = new TimeSpan(0, 2, 0);
                wh.ReliableSession.InactivityTimeout = new TimeSpan(0, 1, 0);
                wh.ReliableSession.Enabled           = true;
                factory = new ChannelFactory <T>(wh, EPD);
                factory.Credentials.ServiceCertificate.Authentication.CustomCertificateValidator = new MyX509Validator();
                factory.Credentials.ServiceCertificate.Authentication.CertificateValidationMode  = X509CertificateValidationMode.Custom;
                factory.Credentials.UserName.UserName = strUserName;
                factory.Credentials.UserName.Password = strPassword;
                factory = new ChannelFactory <T>(wh, EPD);
                SetCredentialsByID(factory.Credentials, strUserName, strPassword);
            }
            else
            {
                factory = (ChannelFactory <T>)dicFactory[URL];
            }
            T t = factory.CreateChannel();

            DicChannel.Remove(URL);
            DicChannel.Add(URL, (IClientChannel)t);
            try
            {
                ((IClientChannel)t).Open();
            }
            catch
            {
            }
            return(t);
        }
        public void ReadConfiguration()
        {
            ServiceModelSectionGroup config = (ServiceModelSectionGroup)ConfigurationManager.OpenExeConfiguration("Test/config/client.endpoint").GetSectionGroup("system.serviceModel");
            AddressHeaderCollection  col    = config.Client.Endpoints [0].Headers.Headers;

            Assert.AreEqual(2, col.Count, "count");

            AddressHeader header = col [0];

            Assert.AreEqual("Header1", header.Name, "name");
            Assert.AreEqual("", header.Namespace, "name");

            header = col [1];
            Assert.AreEqual("Header2", header.Name, "name");
            Assert.AreEqual("uri:my.custom.manespace", header.Namespace, "name");
        }
		public EndpointAddress (
			Uri uri, EndpointIdentity identity,
			AddressHeaderCollection headers,
			XmlDictionaryReader metadataReader,
			XmlDictionaryReader extensionReader)
		{	
			if (uri == null)
				throw new ArgumentNullException ("uri");
			if (!uri.IsAbsoluteUri)
				throw new ArgumentException ("The argument uri must be absolute");
			this.address = uri;
			this.identity = identity;
			this.headers = headers;
			metadata_reader = metadataReader;
			extension_reader = extensionReader;
		}
Esempio n. 23
0
        public static void SnippetReadFromVersionToString()
        {
            AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader("specialservice1", "http://localhost:8000/service", 1);
            AddressHeader addressHeader2 = AddressHeader.CreateAddressHeader("specialservice2", "http://localhost:8000/service", 2);

            AddressHeader[] addressHeaders = new AddressHeader[2] {
                addressHeader1, addressHeader2
            };
            AddressHeaderCollection headers = new AddressHeaderCollection(addressHeaders);

            EndpointAddress endpointAddress = new EndpointAddress(
                new Uri("http://localhost:8003/servicemodelsamples/service/incode/identity"), addressHeaders);

            // <Snippet27>
            string URIstring = endpointAddress.ToString();
            // </Snippet27>
        }
Esempio n. 24
0
        public void ServiceModel()
        {
            AddressHeaderCollection ahc = new AddressHeaderCollection();

            try {
                ahc.FindAll(null, null);
            }
            catch (NotImplementedException) {
                // feature is not available, but the symbol itself is needed
            }

            try {
                FaultException.CreateFault(null, String.Empty, null);
            }
            catch (NotImplementedException) {
                // feature is not available, but the symbol itself is needed
            }
        }
Esempio n. 25
0
        public void ServiceModel()
        {
            AddressHeaderCollection ahc = new AddressHeaderCollection();

            try {
                ahc.FindAll("name", "namespace");
            }
            catch (NotImplementedException) {
                // feature is not available, but the symbol itself is needed
            }

            try {
                FaultException.CreateFault(new TestFault(), String.Empty, Array.Empty <Type> ());
            }
            catch (NotImplementedException) {
                // feature is not available, but the symbol itself is needed
            }
        }
Esempio n. 26
0
        public static void SnippetHeaders()
        {
            //<Snippet14>
            AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader("specialservice1", "http://localhost:8000/service", 1);
            AddressHeader addressHeader2 = AddressHeader.CreateAddressHeader("specialservice2", "http://localhost:8000/service", 2);

            AddressHeader[] addressHeaders = new AddressHeader[2] {
                addressHeader1, addressHeader2
            };
            AddressHeaderCollection headers          = new AddressHeaderCollection(addressHeaders);
            EndpointIdentity        endpointIdentity =
                EndpointIdentity.CreateUpnIdentity(WindowsIdentity.GetCurrent().Name);
            EndpointAddress endpointAddress = new EndpointAddress(
                new Uri
                    ("http://localhost:8003/servicemodelsamples/service/incode/identity"),
                endpointIdentity, addressHeaders);

            AddressHeaderCollection headerCollection = endpointAddress.Headers;
            //</Snippet14>
        }
Esempio n. 27
0
 public EndpointAddress(
     Uri uri, EndpointIdentity identity,
     AddressHeaderCollection headers,
     XmlDictionaryReader metadataReader,
     XmlDictionaryReader extensionReader)
 {
     if (uri == null)
     {
         throw new ArgumentNullException("uri");
     }
     if (!uri.IsAbsoluteUri)
     {
         throw new ArgumentException("The argument uri must be absolute");
     }
     this.address     = uri;
     this.identity    = identity;
     this.headers     = headers;
     metadata_reader  = metadataReader;
     extension_reader = extensionReader;
 }
Esempio n. 28
0
        /// <summary>
        /// Creates the address headers.
        /// </summary>
        /// <returns></returns>
        public AddressHeaderCollection CreateAddressHeaders()
        {
            if (_headers != null)
            {
                return(_headers);
            }

            lock (SyncLock)
            {
                if (_headers != null)
                {
                    return(_headers);
                }

                var element = new AddressHeaderCollectionElement();
                Deserialize(element);
                _headers = element.Headers;

                return(_headers);
            }
        }
Esempio n. 29
0
        public static void SnippetWriteToAddressingVersionXmlWriter()
        {
            AddressHeader addressHeader1 = AddressHeader.CreateAddressHeader("specialservice1", "http://localhost:8000/service", 1);
            AddressHeader addressHeader2 = AddressHeader.CreateAddressHeader("specialservice2", "http://localhost:8000/service", 2);

            AddressHeader[] addressHeaders = new AddressHeader[2] {
                addressHeader1, addressHeader2
            };
            AddressHeaderCollection headers = new AddressHeaderCollection(addressHeaders);

            EndpointAddress endpointAddress = new EndpointAddress(
                new Uri("http://localhost:8003/servicemodelsamples/service/incode/identity"), addressHeaders);

            // <Snippet32>
            XmlWriter writer = XmlWriter.Create("addressdata.xml");

            endpointAddress.WriteTo(
                AddressingVersion.WSAddressing10,
                writer);
            writer.Close();
            // </Snippet32>
        }
 internal EndpointAddress(System.Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlDictionaryReader metadataReader, XmlDictionaryReader extensionReader, XmlDictionaryReader pspReader)
 {
     EndpointIdentity identity2;
     int num;
     if (uri == null)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("uri");
     }
     XmlBuffer buffer = null;
     this.PossiblyPopulateBuffer(metadataReader, ref buffer, out this.metadataSection);
     buffer = ReadExtensions(extensionReader, null, buffer, out identity2, out num);
     if ((identity != null) && (identity2 != null))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("MultipleIdentities"), "extensionReader"));
     }
     this.PossiblyPopulateBuffer(pspReader, ref buffer, out this.pspSection);
     if (buffer != null)
     {
         buffer.Close();
     }
     this.Init(uri, identity ?? identity2, headers, buffer, this.metadataSection, num, this.pspSection);
 }
Esempio n. 31
0
        internal EndpointAddress(System.Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlDictionaryReader metadataReader, XmlDictionaryReader extensionReader, XmlDictionaryReader pspReader)
        {
            EndpointIdentity identity2;
            int num;

            if (uri == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("uri");
            }
            XmlBuffer buffer = null;

            this.PossiblyPopulateBuffer(metadataReader, ref buffer, out this.metadataSection);
            buffer = ReadExtensions(extensionReader, null, buffer, out identity2, out num);
            if ((identity != null) && (identity2 != null))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(System.ServiceModel.SR.GetString("MultipleIdentities"), "extensionReader"));
            }
            this.PossiblyPopulateBuffer(pspReader, ref buffer, out this.pspSection);
            if (buffer != null)
            {
                buffer.Close();
            }
            this.Init(uri, identity ?? identity2, headers, buffer, this.metadataSection, num, this.pspSection);
        }
Esempio n. 32
0
        /// <summary>
        /// Sends a CyberSource transaction request.
        /// </summary>
        /// <param name="config">Configuration object to use.</param>
		/// <param name="requestMessage">RequestMessage object containing the request.</param>
		/// <returns>ReplyMessage containing the reply.</returns>
        public static ReplyMessage RunTransaction(
            Configuration config, RequestMessage requestMessage)
        {

            Logger logger = null;
            TransactionProcessorClient proc = null;
			try
			{

                DetermineEffectiveMerchantID(ref config, requestMessage);
                SetVersionInformation(requestMessage);
                logger = PrepareLog(config);
                SetConnectionLimit(config);


                CustomBinding currentBinding = getWCFCustomBinding();


                //Setup endpoint Address with dns identity
                AddressHeaderCollection headers = new AddressHeaderCollection();
                EndpointAddress endpointAddress = new EndpointAddress( new Uri(config.EffectiveServerURL), EndpointIdentity.CreateDnsIdentity(config.EffectivePassword), headers );
                
                //Get instance of service
                using( proc = new TransactionProcessorClient(currentBinding, endpointAddress)){
                
                    //Set protection level to sign only
                    proc.Endpoint.Contract.ProtectionLevel = System.Net.Security.ProtectionLevel.Sign;

                    // set the timeout
                    TimeSpan timeOut = new TimeSpan(0, 0, 0, config.Timeout, 0);
                    currentBinding.SendTimeout = timeOut;
              
                    //add certificate credentials
                    string keyFilePath = Path.Combine(config.KeysDirectory,config.EffectiveKeyFilename);
                    proc.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(keyFilePath,config.EffectivePassword, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);

                    proc.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;

                    // Changes for SHA2 certificates support
                    X509Certificate2Collection collection = new X509Certificate2Collection();
                    collection.Import(keyFilePath, config.EffectivePassword, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);

                    foreach (X509Certificate2 cert1 in collection)
                    {
                        if (cert1.Subject.Contains(config.MerchantID))
                        {
                            proc.ClientCredentials.ClientCertificate.Certificate = cert1;
                            proc.ClientCredentials.ServiceCertificate.DefaultCertificate = cert1;
                            break;
                        }
                    }

                    // send request now
                    // Changes for NGT-3035
                    XmlNode req = SerializeObjectToXmlNode(requestMessage);
                    if (logger != null)
                    {
                        logger.LogRequest(req, config.Demo);
                    }                   
                    
                    ReplyMessage reply = proc.runTransaction(requestMessage);
                    XmlNode rep = SerializeObjectToXmlNode(reply);
                    if (logger != null)
                    {
                        logger.LogReply(rep, config.Demo);
                    }  
                   
                    return (reply);
                }
			}
		    catch (Exception e)
            {
                if (logger != null)
                {
                    logger.LogException(e);
                }
                if (proc != null)
                {
                    proc.Abort();
                }
                throw;
            }
            finally
            {
                if (proc != null)
                {
                    proc.Close();
                }
            }
        }
Esempio n. 33
0
        private void Init(AddressingVersion version, Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlBuffer buffer, int metadataSection, int extensionSection, int pspSection)
        {
            if (!uri.IsAbsoluteUri)
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("uri", SR.UriMustBeAbsolute);

            _addressingVersion = version;
            _uri = uri;
            _identity = identity;
            _headers = headers;
            _buffer = buffer;
            _metadataSection = metadataSection;
            _extensionSection = extensionSection;
            _pspSection = pspSection;

            if (version != null)
            {
                _isAnonymous = uri == version.AnonymousUri;
                _isNone = uri == version.NoneUri;
            }
            else
            {
                _isAnonymous = object.ReferenceEquals(uri, AnonymousUri) || uri == AnonymousUri;
                _isNone = object.ReferenceEquals(uri, NoneUri) || uri == NoneUri;
            }
            if (_isAnonymous)
            {
                _uri = AnonymousUri;
            }
            if (_isNone)
            {
                _uri = NoneUri;
            }
        }
		protected override void DeserializeElement (
			XmlReader reader, bool serializeCollectionKey) {
			reader.MoveToContent ();
			_headers = new AddressHeaderCollection (DeserializeAddressHeaders (reader));
		}
Esempio n. 35
0
 public EndpointAddress(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers)
     : this(uri, identity, headers, null, null)
 {
 }
Esempio n. 36
0
        static bool ReadContentsFrom10(XmlDictionaryReader reader, out Uri uri, out AddressHeaderCollection headers, out EndpointIdentity identity, out XmlBuffer buffer, out int metadataSection, out int extensionSection)
        {
            buffer = null;
            extensionSection = -1;
            metadataSection = -1;

            // Cache address string
            if (!reader.IsStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace))
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.GetString(SR.UnexpectedElementExpectingElement, reader.LocalName, reader.NamespaceURI, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value)));
            string address = reader.ReadElementContentAsString();

            // Headers
            if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespace))
            {
                headers = AddressHeaderCollection.ReadServiceParameters(reader);
            }
            else
            {
                headers = null;
            }

            // Metadata
            if (reader.IsStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace))
            {
                reader.ReadFullStartElement();  // the wsa10:Metadata element is never stored in the buffer
                buffer = new XmlBuffer(short.MaxValue);
                metadataSection = 0;
                XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);
                writer.WriteStartElement(DummyName, DummyNamespace);
                while (reader.NodeType != XmlNodeType.EndElement && !reader.EOF)
                {
                    writer.WriteNode(reader, true);
                }
                writer.Flush();
                buffer.CloseSection();
                reader.ReadEndElement();
            }

            // Extensions
            buffer = ReadExtensions(reader, AddressingVersion.WSAddressing10, buffer, out identity, out extensionSection);
            if (buffer != null)
            {
                buffer.Close();
            }

            // Process Address
            if (address == Addressing10Strings.Anonymous)
            {
                uri = AddressingVersion.WSAddressing10.AnonymousUri;
                if (headers == null && identity == null)
                {
                    return true;
                }
            }
            else if (address == Addressing10Strings.NoneAddress)
            {
                uri = AddressingVersion.WSAddressing10.NoneUri;
                return false;
            }
            else
            {
                if (!Uri.TryCreate(address, UriKind.Absolute, out uri))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.InvalidUriValue, address, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value)));
                }
            }
            return false;
        }
Esempio n. 37
0
        static bool ReadContentsFrom10(XmlDictionaryReader reader, out Uri uri, out AddressHeaderCollection headers, out EndpointIdentity identity, out XmlBuffer buffer, out int metadataSection, out int extensionSection)
        {
            buffer           = null;
            extensionSection = -1;
            metadataSection  = -1;

            // Cache address string
            if (!reader.IsStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.Format(SR.UnexpectedElementExpectingElement, reader.LocalName, reader.NamespaceURI, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value)));
            }
            string address = reader.ReadElementContentAsString();

            // Headers
            if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespace))
            {
                headers = AddressHeaderCollection.ReadServiceParameters(reader);
            }
            else
            {
                headers = null;
            }

            // Metadata
            if (reader.IsStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace))
            {
                reader.ReadFullStartElement();  // the wsa10:Metadata element is never stored in the buffer
                buffer          = new XmlBuffer(short.MaxValue);
                metadataSection = 0;
                XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);
                writer.WriteStartElement(DummyName, DummyNamespace);
                while (reader.NodeType != XmlNodeType.EndElement && !reader.EOF)
                {
                    writer.WriteNode(reader, true);
                }
                writer.Flush();
                buffer.CloseSection();
                reader.ReadEndElement();
            }

            // Extensions
            buffer = ReadExtensions(reader, AddressingVersion.WSAddressing10, buffer, out identity, out extensionSection);
            if (buffer != null)
            {
                buffer.Close();
            }

            // Process Address
            if (address == Addressing10Strings.Anonymous)
            {
                uri = AddressingVersion.WSAddressing10.AnonymousUri;
                if (headers == null && identity == null)
                {
                    return(true);
                }
            }
            else if (address == Addressing10Strings.NoneAddress)
            {
                uri = AddressingVersion.WSAddressing10.NoneUri;
                return(false);
            }
            else
            {
                if (!Uri.TryCreate(address, UriKind.Absolute, out uri))
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.Format(SR.InvalidUriValue, address, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value)));
                }
            }
            return(false);
        }
		public EndpointAddress (Uri uri, EndpointIdentity identity, AddressHeaderCollection headers)
			: this (uri, identity, headers, null, null) {}
 private static bool ReadContentsFrom10(XmlDictionaryReader reader, out System.Uri uri, out AddressHeaderCollection headers, out EndpointIdentity identity, out XmlBuffer buffer, out int metadataSection, out int extensionSection)
 {
     buffer = null;
     extensionSection = -1;
     metadataSection = -1;
     if (!reader.IsStartElement(XD.AddressingDictionary.Address, XD.Addressing10Dictionary.Namespace))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, System.ServiceModel.SR.GetString("UnexpectedElementExpectingElement", new object[] { reader.LocalName, reader.NamespaceURI, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value })));
     }
     string uriString = reader.ReadElementContentAsString();
     if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, XD.Addressing10Dictionary.Namespace))
     {
         headers = AddressHeaderCollection.ReadServiceParameters(reader);
     }
     else
     {
         headers = null;
     }
     if (reader.IsStartElement(XD.Addressing10Dictionary.Metadata, XD.Addressing10Dictionary.Namespace))
     {
         reader.ReadFullStartElement();
         buffer = new XmlBuffer(0x7fff);
         metadataSection = 0;
         XmlDictionaryWriter writer = buffer.OpenSection(reader.Quotas);
         writer.WriteStartElement("Dummy", "http://Dummy");
         while ((reader.NodeType != XmlNodeType.EndElement) && !reader.EOF)
         {
             writer.WriteNode(reader, true);
         }
         writer.Flush();
         buffer.CloseSection();
         reader.ReadEndElement();
     }
     buffer = ReadExtensions(reader, AddressingVersion.WSAddressing10, buffer, out identity, out extensionSection);
     if (buffer != null)
     {
         buffer.Close();
     }
     if (uriString == "http://www.w3.org/2005/08/addressing/anonymous")
     {
         uri = AddressingVersion.WSAddressing10.AnonymousUri;
         if ((headers == null) && (identity == null))
         {
             return true;
         }
     }
     else
     {
         if (uriString == "http://www.w3.org/2005/08/addressing/none")
         {
             uri = AddressingVersion.WSAddressing10.NoneUri;
             return false;
         }
         if (!System.Uri.TryCreate(uriString, UriKind.Absolute, out uri))
         {
             throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidUriValue", new object[] { uriString, XD.AddressingDictionary.Address.Value, XD.Addressing10Dictionary.Namespace.Value })));
         }
     }
     return false;
 }
Esempio n. 40
0
      public static ResourceUriHeader GetFrom(AddressHeaderCollection headerCollection)
      {
		 return (ResourceUriHeader)headerCollection.FindHeader(ElementName, ManagementNamespaces.Namespace);
      }
 private void Init(System.Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlBuffer buffer, int metadataSection, int extensionSection, int pspSection)
 {
     this.Init(null, uri, identity, headers, buffer, metadataSection, extensionSection, pspSection);
 }
Esempio n. 42
0
        internal EndpointAddress(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlDictionaryReader metadataReader, XmlDictionaryReader extensionReader, XmlDictionaryReader pspReader)
        {
            if (uri == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("uri");
            }

            XmlBuffer buffer = null;
            PossiblyPopulateBuffer(metadataReader, ref buffer, out metadataSection);

            EndpointIdentity ident2;
            int extSection;
            buffer = ReadExtensions(extensionReader, null, buffer, out ident2, out extSection);

            if (identity != null && ident2 != null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentException(SR.GetString(SR.MultipleIdentities), "extensionReader"));
            }

            PossiblyPopulateBuffer(pspReader, ref buffer, out pspSection);

            if (buffer != null)
            {
                buffer.Close();
            }

            Init(uri, identity ?? ident2, headers, buffer, metadataSection, extSection, pspSection);
        }
Esempio n. 43
0
        static bool ReadContentsFrom200408(XmlDictionaryReader reader, out Uri uri, out AddressHeaderCollection headers, out EndpointIdentity identity, out XmlBuffer buffer, out int metadataSection, out int extensionSection, out int pspSection)
        {
            buffer = null;
            headers = null;
            extensionSection = -1;
            metadataSection = -1;
            pspSection = -1;

            // Cache address string
            reader.MoveToContent();
            if (!reader.IsStartElement(XD.AddressingDictionary.Address, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, SR.GetString(SR.UnexpectedElementExpectingElement, reader.LocalName, reader.NamespaceURI, XD.AddressingDictionary.Address.Value, XD.Addressing200408Dictionary.Namespace.Value)));
            }
            string address = reader.ReadElementContentAsString();

            // ReferenceProperites
            reader.MoveToContent();
            if (reader.IsStartElement(XD.AddressingDictionary.ReferenceProperties, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
            {
                headers = AddressHeaderCollection.ReadServiceParameters(reader, true);
            }

            // ReferenceParameters
            reader.MoveToContent();
            if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
            {
                if (headers != null)
                {
                    List<AddressHeader> headerList = new List<AddressHeader>();
                    foreach (AddressHeader ah in headers)
                    {
                        headerList.Add(ah);
                    }
                    AddressHeaderCollection tmp = AddressHeaderCollection.ReadServiceParameters(reader);
                    foreach (AddressHeader ah in tmp)
                    {
                        headerList.Add(ah);
                    }
                    headers = new AddressHeaderCollection(headerList);
                }
                else
                {
                    headers = AddressHeaderCollection.ReadServiceParameters(reader);
                }
            }

            XmlDictionaryWriter bufferWriter = null;

            // PortType
            reader.MoveToContent();
            if (reader.IsStartElement(XD.AddressingDictionary.PortType, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
            {
                if (bufferWriter == null)
                {
                    if (buffer == null)
                        buffer = new XmlBuffer(short.MaxValue);
                    bufferWriter = buffer.OpenSection(reader.Quotas);
                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
                }
                bufferWriter.WriteNode(reader, true);
            }

            // ServiceName
            reader.MoveToContent();
            if (reader.IsStartElement(XD.AddressingDictionary.ServiceName, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
            {
                if (bufferWriter == null)
                {
                    if (buffer == null)
                        buffer = new XmlBuffer(short.MaxValue);
                    bufferWriter = buffer.OpenSection(reader.Quotas);
                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
                }
                bufferWriter.WriteNode(reader, true);
            }

            // Policy
            reader.MoveToContent();
            while (reader.IsNamespaceUri(XD.PolicyDictionary.Namespace))
            {
                if (bufferWriter == null)
                {
                    if (buffer == null)
                        buffer = new XmlBuffer(short.MaxValue);
                    bufferWriter = buffer.OpenSection(reader.Quotas);
                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
                }
                bufferWriter.WriteNode(reader, true);
                reader.MoveToContent();
            }

            // Finish PSP
            if (bufferWriter != null)
            {
                bufferWriter.WriteEndElement();
                buffer.CloseSection();
                pspSection = buffer.SectionCount - 1;
                bufferWriter = null;
            }
            else
            {
                pspSection = -1;
            }


            // Metadata
            if (reader.IsStartElement(System.ServiceModel.Description.MetadataStrings.MetadataExchangeStrings.Metadata,
                                      System.ServiceModel.Description.MetadataStrings.MetadataExchangeStrings.Namespace))
            {
                if (bufferWriter == null)
                {
                    if (buffer == null)
                        buffer = new XmlBuffer(short.MaxValue);
                    bufferWriter = buffer.OpenSection(reader.Quotas);
                    bufferWriter.WriteStartElement(DummyName, DummyNamespace);
                }
                bufferWriter.WriteNode(reader, true);
            }

            // Finish metadata
            if (bufferWriter != null)
            {
                bufferWriter.WriteEndElement();
                buffer.CloseSection();
                metadataSection = buffer.SectionCount - 1;
                bufferWriter = null;
            }
            else
            {
                metadataSection = -1;
            }

            // Extensions
            reader.MoveToContent();
            buffer = ReadExtensions(reader, AddressingVersion.WSAddressingAugust2004, buffer, out identity, out extensionSection);

            // Finished reading
            if (buffer != null)
                buffer.Close();

            // Process Address
            if (address == Addressing200408Strings.Anonymous)
            {
                uri = AddressingVersion.WSAddressingAugust2004.AnonymousUri;
                if (headers == null && identity == null)
                    return true;
            }
            else
            {
                if (!Uri.TryCreate(address, UriKind.Absolute, out uri))
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(SR.GetString(SR.InvalidUriValue, address, XD.AddressingDictionary.Address.Value, AddressingVersion.WSAddressingAugust2004.Namespace)));
            }
            return false;
        }
 internal void InitializeFrom(AddressHeaderCollection headers)
 {
     SetPropertyValueIfNotDefaultValue(ConfigurationStrings.Headers, headers);
 }
 private void DeserializeElementCore(XmlReader reader)
 {
     this.Headers = AddressHeaderCollection.ReadServiceParameters(XmlDictionaryReader.CreateDictionaryReader(reader));
 }
Esempio n. 46
0
 void Init(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlBuffer buffer, int metadataSection, int extensionSection, int pspSection)
 {
     Init(null, uri, identity, headers, buffer, metadataSection, extensionSection, pspSection);
 }
 private void Init(AddressingVersion version, System.Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlBuffer buffer, int metadataSection, int extensionSection, int pspSection)
 {
     if (!uri.IsAbsoluteUri)
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("uri", System.ServiceModel.SR.GetString("UriMustBeAbsolute"));
     }
     this.uri = uri;
     this.identity = identity;
     this.headers = headers;
     this.buffer = buffer;
     this.metadataSection = metadataSection;
     this.extensionSection = extensionSection;
     this.pspSection = pspSection;
     if (version != null)
     {
         this.isAnonymous = uri == version.AnonymousUri;
         this.isNone = uri == version.NoneUri;
     }
     else
     {
         this.isAnonymous = object.ReferenceEquals(uri, AnonymousUri) || (uri == AnonymousUri);
         this.isNone = object.ReferenceEquals(uri, NoneUri) || (uri == NoneUri);
     }
     if (this.isAnonymous)
     {
         this.uri = AnonymousUri;
     }
     if (this.isNone)
     {
         this.uri = NoneUri;
     }
 }
Esempio n. 48
0
 public EndpointAddress(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlDictionaryReader metadataReader, XmlDictionaryReader extensionReader);
Esempio n. 49
0
        /// <summary>
        /// Sends a CyberSource transaction request.
        /// </summary>
        /// <param name="config">Configuration object to use.</param>
        /// <param name="request">Hashtable containing the request fields and their values.</param>
        /// <returns>Hashtable containing the reply fields and their values.</returns>
        public static Hashtable RunTransaction(
            Configuration config, Hashtable request)
        {
            Logger logger=null;
            NVPTransactionProcessorClient proc=null;
            try
            {
                DetermineEffectiveMerchantID(ref config, request);
                SetVersionInformation(request);
                logger = PrepareLog(config);
                SetConnectionLimit(config);

                //Setup custom binding with HTTPS + Body Signing 
                CustomBinding currentBinding = getWCFCustomBinding();

                //Setup endpoint Address with dns identity
                AddressHeaderCollection headers = new AddressHeaderCollection();
                EndpointAddress endpointAddress = new EndpointAddress(new Uri(config.EffectiveServerURL), EndpointIdentity.CreateDnsIdentity(config.EffectivePassword), headers);

                //Get instance of service
                using (proc = new NVPTransactionProcessorClient(currentBinding, endpointAddress))
                {

                    //Set protection level to sign only
                    proc.Endpoint.Contract.ProtectionLevel = System.Net.Security.ProtectionLevel.Sign;

                    // set the timeout
                    TimeSpan timeOut = new TimeSpan(0, 0, 0, config.Timeout, 0);
                    currentBinding.SendTimeout = timeOut;


                    string keyFilePath = Path.Combine(config.KeysDirectory, config.EffectiveKeyFilename);
                    proc.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(keyFilePath, config.EffectivePassword, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);

                    proc.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.None;
                    proc.ClientCredentials.ServiceCertificate.DefaultCertificate = proc.ClientCredentials.ClientCertificate.Certificate;

                    if (logger != null)
                    {
                        logger.LogRequest(request, config.Demo);
                    }

                    // send request now, converting the hashtable request into
                    // a string, and the string reply back into a hashtable.

                    string resp = proc.runTransaction(Hash2String(request));


                    Hashtable reply = String2Hash(resp);

                    if (logger != null)
                    {
                        logger.LogReply(reply, config.Demo);
                    }

                    return (reply);
                }
            }
            catch (Exception e)
            {
                if (logger != null)
                {
                    logger.LogException(e);
                }
                if (proc != null)
                {
                    proc.Abort();
                }
                throw;
            }
            finally
            {
                if (proc != null)
                {
                    proc.Close();
                }
            }
        }
Esempio n. 50
0
 EndpointAddress(AddressingVersion version, Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlBuffer buffer, int metadataSection, int extensionSection, int pspSection)
 {
     Init(version, uri, identity, headers, buffer, metadataSection, extensionSection, pspSection);
 }
Esempio n. 51
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.ServiceModel.EndpointAddress"/> class with a specified URI, identity, and header collection.
 /// </summary>
 /// <param name="uri">The <see cref="T:System.Uri"/> that identifies the endpoint location.</param><param name="identity">The <see cref="T:System.ServiceModel.EndpointIdentity"/> for the endpoint.</param><param name="headers">The <see cref="T:System.ServiceModel.Channels.AddressHeaderCollection"/> that contains address information used to interact with the endpoint.</param>
 public EndpointAddress(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers);
 public EndpointAddress(System.Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlDictionaryReader metadataReader, XmlDictionaryReader extensionReader) : this(uri, identity, headers, metadataReader, extensionReader, null)
 {
 }
 private EndpointAddress(AddressingVersion version, System.Uri uri, EndpointIdentity identity, AddressHeaderCollection headers, XmlBuffer buffer, int metadataSection, int extensionSection, int pspSection)
 {
     this.Init(version, uri, identity, headers, buffer, metadataSection, extensionSection, pspSection);
 }
 private static bool ReadContentsFrom200408(XmlDictionaryReader reader, out System.Uri uri, out AddressHeaderCollection headers, out EndpointIdentity identity, out XmlBuffer buffer, out int metadataSection, out int extensionSection, out int pspSection)
 {
     buffer = null;
     headers = null;
     extensionSection = -1;
     metadataSection = -1;
     pspSection = -1;
     reader.MoveToContent();
     if (!reader.IsStartElement(XD.AddressingDictionary.Address, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(CreateXmlException(reader, System.ServiceModel.SR.GetString("UnexpectedElementExpectingElement", new object[] { reader.LocalName, reader.NamespaceURI, XD.AddressingDictionary.Address.Value, XD.Addressing200408Dictionary.Namespace.Value })));
     }
     string uriString = reader.ReadElementContentAsString();
     reader.MoveToContent();
     if (reader.IsStartElement(XD.AddressingDictionary.ReferenceProperties, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
     {
         headers = AddressHeaderCollection.ReadServiceParameters(reader, true);
     }
     reader.MoveToContent();
     if (reader.IsStartElement(XD.AddressingDictionary.ReferenceParameters, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
     {
         if (headers != null)
         {
             List<AddressHeader> addressHeaders = new List<AddressHeader>();
             foreach (AddressHeader header in headers)
             {
                 addressHeaders.Add(header);
             }
             foreach (AddressHeader header2 in AddressHeaderCollection.ReadServiceParameters(reader))
             {
                 addressHeaders.Add(header2);
             }
             headers = new AddressHeaderCollection(addressHeaders);
         }
         else
         {
             headers = AddressHeaderCollection.ReadServiceParameters(reader);
         }
     }
     XmlDictionaryWriter writer = null;
     reader.MoveToContent();
     if (reader.IsStartElement(XD.AddressingDictionary.PortType, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
     {
         if (writer == null)
         {
             if (buffer == null)
             {
                 buffer = new XmlBuffer(0x7fff);
             }
             writer = buffer.OpenSection(reader.Quotas);
             writer.WriteStartElement("Dummy", "http://Dummy");
         }
         writer.WriteNode(reader, true);
     }
     reader.MoveToContent();
     if (reader.IsStartElement(XD.AddressingDictionary.ServiceName, AddressingVersion.WSAddressingAugust2004.DictionaryNamespace))
     {
         if (writer == null)
         {
             if (buffer == null)
             {
                 buffer = new XmlBuffer(0x7fff);
             }
             writer = buffer.OpenSection(reader.Quotas);
             writer.WriteStartElement("Dummy", "http://Dummy");
         }
         writer.WriteNode(reader, true);
     }
     reader.MoveToContent();
     while (reader.IsNamespaceUri(XD.PolicyDictionary.Namespace))
     {
         if (writer == null)
         {
             if (buffer == null)
             {
                 buffer = new XmlBuffer(0x7fff);
             }
             writer = buffer.OpenSection(reader.Quotas);
             writer.WriteStartElement("Dummy", "http://Dummy");
         }
         writer.WriteNode(reader, true);
         reader.MoveToContent();
     }
     if (writer != null)
     {
         writer.WriteEndElement();
         buffer.CloseSection();
         pspSection = buffer.SectionCount - 1;
         writer = null;
     }
     else
     {
         pspSection = -1;
     }
     if (reader.IsStartElement("Metadata", "http://schemas.xmlsoap.org/ws/2004/09/mex"))
     {
         if (writer == null)
         {
             if (buffer == null)
             {
                 buffer = new XmlBuffer(0x7fff);
             }
             writer = buffer.OpenSection(reader.Quotas);
             writer.WriteStartElement("Dummy", "http://Dummy");
         }
         writer.WriteNode(reader, true);
     }
     if (writer != null)
     {
         writer.WriteEndElement();
         buffer.CloseSection();
         metadataSection = buffer.SectionCount - 1;
         writer = null;
     }
     else
     {
         metadataSection = -1;
     }
     reader.MoveToContent();
     buffer = ReadExtensions(reader, AddressingVersion.WSAddressingAugust2004, buffer, out identity, out extensionSection);
     if (buffer != null)
     {
         buffer.Close();
     }
     if (uriString == "http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous")
     {
         uri = AddressingVersion.WSAddressingAugust2004.AnonymousUri;
         if ((headers == null) && (identity == null))
         {
             return true;
         }
     }
     else if (!System.Uri.TryCreate(uriString, UriKind.Absolute, out uri))
     {
         throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new XmlException(System.ServiceModel.SR.GetString("InvalidUriValue", new object[] { uriString, XD.AddressingDictionary.Address.Value, AddressingVersion.WSAddressingAugust2004.Namespace })));
     }
     return false;
 }
Esempio n. 55
0
 public static IdentifierHeader GetFrom(AddressHeaderCollection headerCollection)
 {
    return (IdentifierHeader)headerCollection.FindHeader(ElementName, EventingActions.Namespace);
 }