Esempio n. 1
0
        ///// <summary>
        ///// 创建客户端服务
        ///// </summary>
        //public static HSSEService.HSSEServiceClient CreateServiceClient()
        //{
        //    string address = ConfigurationManager.AppSettings["endpoint"];
        //    var proxy = new HSSEService.HSSEServiceClient();
        //    ConfigEndpointAddress<HSSEService.HSSEService>(proxy, address);
        //    return proxy;
        //}

        /// <summary>
        /// 根据web.config中服务器端主机地址配置服务通道的终端地址。
        /// </summary>
        /// <typeparam name="TChannel">通道类型</typeparam>
        /// <param name="proxy">代理</param>
        /// <param name="endpointAddress">服务访问地址</param>
        public static void ConfigEndpointAddress <TChannel>(System.ServiceModel.ClientBase <TChannel> proxy, string endpointAddress)
            where TChannel : class
        {
            Uri             endpointUri     = new Uri(endpointAddress);
            EndpointAddress endPointAddress = new EndpointAddress(endpointUri);

            proxy.Endpoint.Address = endPointAddress;
        }
Esempio n. 2
0
        public static void AddHeaders <T>(System.ServiceModel.ClientBase <T> client, string username, string password, string uygulamaKullaniciAdi) where T : class
        {
            EndpointAddressBuilder addressBuilder = new EndpointAddressBuilder(client.Endpoint.Address);

            addressBuilder.Headers.Add(AddressHeader.CreateAddressHeader("KullaniciAdi", string.Empty, username));
            addressBuilder.Headers.Add(AddressHeader.CreateAddressHeader("Parola", string.Empty, password));
            addressBuilder.Headers.Add(AddressHeader.CreateAddressHeader("UygulamaKullaniciAdi", string.Empty, uygulamaKullaniciAdi));

            client.Endpoint.Address = addressBuilder.ToEndpointAddress();
        }
Esempio n. 3
0
 public static void Using <TChannel>(this System.ServiceModel.ClientBase <TChannel> client, Action <System.ServiceModel.ClientBase <TChannel> > work) where TChannel : class
 {
     work(client);
     try
     {
         client.Close();
     }
     catch (Exception e)
     {
         client.Abort();
     }
 }
        private static System.ServiceModel.ClientBase <T> SetupClient <T>(this System.ServiceModel.ClientBase <T> clientBase, string token) where T : class
        {
            var binding = clientBase.Endpoint.Binding as BasicHttpBinding;

            binding.MaxReceivedMessageSize = 1234567890;
            binding.Security.Mode          = BasicHttpSecurityMode.Transport;
            binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Basic;

            clientBase.ClientCredentials.UserName.UserName = "******";
            clientBase.ClientCredentials.UserName.Password = token;

            return(clientBase);
        }
Esempio n. 5
0
        public static TReturn Using <TChannel, TReturn>(this System.ServiceModel.ClientBase <TChannel> client, Func <System.ServiceModel.ClientBase <TChannel>, TReturn> work) where TChannel : class
        {
            var result = default(TReturn);

            result = work(client);
            try
            {
                client.Close();
            }
            catch (Exception e)
            {
                client.Abort();
            }
            return(result);
        }
Esempio n. 6
0
        public static void SetupClientBase <T>(System.ServiceModel.ClientBase <T> client, HttpContext httpContext) where T : class
        {
            var guid        = LoggingHelper.GetInstanceGUID(httpContext, () => new Guid()).GetValueOrDefault();
            var sessionGUID = LoggingHelper.GetSessionGUID(httpContext, httpContext?.Handler as Page, () => new Guid()).GetValueOrDefault();
            var pageGUID    = LoggingHelper.GetPageGUID(httpContext, httpContext?.Handler as Page, () => new Guid()).GetValueOrDefault();
            var bundleGUID  = LoggingHelper.GetBundleGUID(httpContext, () => new Guid()).GetValueOrDefault();

            var newLogElement = new LogElementDTO(
                guid: guid,
                sessionGUID: sessionGUID,
                pageGUID: pageGUID,
                bundleGUID: bundleGUID,
                progressGUID: null,
                unixTimestamp: TimeHelper.UnixTimestamp(),
                logType: LogType.OnSetup,
                element: $"SetupClientBase_{client.Endpoint.Address.Uri}", //LoggingHelper.StripUrlForLRAP(context.Request.RawUrl),
                element2: null,
                value: "",                                                 //SerializationHelper.Serialize(requestParams, SerializationType.Json),
                times: 1,
                unixTimestampEnd: null,
                instanceTime: DateTime.Now,
                stackTrace: null
                );

            var eab = new EndpointAddressBuilder(client.Endpoint.Address);

            eab.Headers.Add(AddressHeader.CreateAddressHeader(Consts.GUIDTag,
                                                              string.Empty,
                                                              guid.ToString()));

            eab.Headers.Add(AddressHeader.CreateAddressHeader(Consts.SessionGUIDTag,
                                                              string.Empty,
                                                              sessionGUID.ToString()));

            eab.Headers.Add(AddressHeader.CreateAddressHeader(Consts.PageGUIDTag,
                                                              string.Empty,
                                                              pageGUID.ToString()));

            eab.Headers.Add(AddressHeader.CreateAddressHeader(Consts.BundleGUIDTag,
                                                              string.Empty,
                                                              bundleGUID.ToString()));

            eab.Headers.Add(AddressHeader.CreateAddressHeader(Consts.ServerGUIDTag,
                                                              string.Empty,
                                                              LoggingHelper.GetServerGUID(httpContext, () => new Guid()).GetValueOrDefault().ToString()));

            client.Endpoint.Address = eab.ToEndpointAddress();
        }
        private static ClientBase <T> InitialClient <T>(System.ServiceModel.ClientBase <T> client) where T : class
        {
            string pfxKeyPath = "";
            string cerKeyPath = "";

            try
            {
                string root = System.Web.HttpContext.Current.Server.MapPath("~");
                pfxKeyPath = root + "/bin/cert.pfx";
                cerKeyPath = root + "/bin/bitaServicebusCert.cer";
                client.ClientCredentials.ServiceCertificate.DefaultCertificate = new X509Certificate2(cerKeyPath);
                Log.Debug("bitaServicebusCert.cer load done");

                if (Configuration.GetInstance().IsLocalMachin())
                {
                    client.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(pfxKeyPath,
                                                                                                  "DpQXmjdDBJif2K76qaEkS", X509KeyStorageFlags.PersistKeySet);
                }
                else
                {
                    client.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(pfxKeyPath,
                                                                                                  "DpQXmjdDBJif2K76qaEkS", X509KeyStorageFlags.MachineKeySet);
                }
                Log.Debug("cert.pfx load done");
                client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode =
                    X509CertificateValidationMode.None;
                Log.Debug("certificate mode set successfully!");

                return(client);
            }
            catch (CryptographicException ex)
            {
                Log.Error("Public or Private Key Not Found; Path:" + pfxKeyPath + " OR " + cerKeyPath);
                Log.Error(ex.StackTrace);
                Log.Debug(ex.Message);
                if (ex.InnerException != null)
                {
                    Log.Error(ex.InnerException.Message);
                    if (ex.InnerException.InnerException != null)
                    {
                        Log.Error(ex.InnerException.InnerException.Message);
                    }
                }
                throw new UserInterfaceException(1002, "خطای داخلی رخ داده است.");
            }
        }
Esempio n. 8
0
        private static void ReplaceServiceUrl <T>(System.ServiceModel.ClientBase <T> service, SystemType systemType) where T : class
        {
            Uri    uri         = new Uri(service.Endpoint.Address.Uri.ToString());
            string hostAndPort = uri.Host;

            if (!uri.IsDefaultPort)
            {
                hostAndPort += ":" + uri.Port;
            }
            string url = uri.ToString();

            if (systemType == SystemType.CprBroker)
            {
                url = url.Replace(hostAndPort, "localhost:1551");
            }
            else
            {
                url = url.Replace(hostAndPort, "localhost:1552");
            }
            service.Endpoint.Address = new EndpointAddress(url);
        }
Esempio n. 9
0
 private void logClientInfo <T>(System.ServiceModel.ClientBase <T> client) where T : class
 {
     System.ServiceModel.Description.ServiceEndpoint se = client.Endpoint;
     AppLib.WriteLogInfoMessage("Client Info: type: {0}, address {1}; binding: {2}; contract: {3}", typeof(T).Name, se.Address, se.Binding.Name, se.Contract.Name);
 }
Esempio n. 10
0
 public TempConvertSoapClientChannel(System.ServiceModel.ClientBase <TempConvertSoap> client) :
     base(client)
 {
 }
Esempio n. 11
0
 /// <summary>
 /// Constructs a new instance of the object
 /// </summary>
 /// <param name="client"></param>
 public ConnectorServiceChannel(System.ServiceModel.ClientBase <IConnectorContract> client) :
     base(client)
 {
 }
Esempio n. 12
0
 public HelloWorldServiceClientChannel(System.ServiceModel.ClientBase <IHelloWorldService> client) :
     base(client)
 {
 }
Esempio n. 13
0
 public Ais7MobileCommonServerCoreXamarinClientChannel(System.ServiceModel.ClientBase <IAis7MobileCommonServerCoreXamarin> client) :
     base(client)
 {
 }
Esempio n. 14
0
 public InvokableServiceClientChannel(System.ServiceModel.ClientBase <IInvocableService> client) :
     base(client)
 {
 }