Exemple #1
0
        private void ParaseConfig(string moduleName)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(moduleName);
            var childList = xmlDoc.SelectNodes("//connection");

            if (childList == null)
            {
                return;
            }
            _pools.Clear();

            foreach (var child in childList)
            {
                XmlElement el = child as XmlElement;
                if (el == null)
                {
                    continue;
                }
                int              gameid     = el.GetAttribute("gameid").ToInt();
                int              serverid   = el.GetAttribute("serverid").ToInt();
                string           ip         = el.GetAttribute("ip");
                int              port       = el.GetAttribute("port").ToInt();
                int              identityId = ToIdentityId(gameid, serverid);
                WcfServiceClient oldValue;
                if (_pools.TryRemove(identityId, out oldValue))
                {
                    oldValue.Dispose();
                }
                var client = new WcfServiceClient(ip, port, identityId);
                _pools.TryAdd(identityId, client);
            }
        }
Exemple #2
0
        public MainPage()
        {
            InitializeComponent();

            Client = new WcfServiceClient(); //ServiceUtil.GetWcfServiceClient();
            Client.loginCompleted += Client_loginCompleted;
        }
Exemple #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            WcfServiceClient client = new WcfServiceClient();

            MessageBox.Show(client.GetData(10, 15));
            client.Close();
        }
Exemple #4
0
        public Form1()
        {
            InitializeComponent();
            WcfClient = new WcfServiceClient();

            WcfClient.loginCompleted   += WcfClient_loginCompleted;
            WcfClient.AddUserCompleted += WcfClient_AddUserCompleted;
        }
Exemple #5
0
        public void ClientOpen()
        {
            String        url        = String.Format(CultureInfo.CurrentCulture, "net.tcp://localhost:12121/LeagueGoServer/WcfService/", "127.0.0.1", 12121);
            NetTcpBinding tcpBinding = new NetTcpBinding()
            {
                Name          = "netTcpBindConfig",
                ReaderQuotas  = XmlDictionaryReaderQuotas.Max,
                ListenBacklog = Int32.MaxValue,

                MaxBufferPoolSize      = Int32.MaxValue,
                MaxConnections         = 10,
                MaxBufferSize          = Int32.MaxValue,
                MaxReceivedMessageSize = Int32.MaxValue,
                PortSharingEnabled     = true,
                CloseTimeout           = TimeSpan.FromSeconds(10),
                OpenTimeout            = TimeSpan.FromSeconds(10),
                ReceiveTimeout         = TimeSpan.FromMinutes(10),
                SendTimeout            = TimeSpan.FromMinutes(10),
                TransactionFlow        = false,
                TransferMode           = TransferMode.Buffered,
                TransactionProtocol    = TransactionProtocol.OleTransactions,
                HostNameComparisonMode = HostNameComparisonMode.StrongWildcard,
                ReliableSession        = new OptionalReliableSession
                {
                    Enabled           = false,
                    Ordered           = true,
                    InactivityTimeout = TimeSpan.FromMinutes(10),
                },
                Security = new NetTcpSecurity
                {
                    Mode    = SecurityMode.None,
                    Message = new MessageSecurityOverTcp
                    {
                        ClientCredentialType = MessageCredentialType.Windows,
                    },
                    Transport = new TcpTransportSecurity
                    {
                        ClientCredentialType = TcpClientCredentialType.Windows,
                        ProtectionLevel      = ProtectionLevel.EncryptAndSign
                    }
                }
            };
            //this.m_instanceContext = new InstanceContext(OccClientServicesCallBack.Instance);
            //this.m_duplexChannel = new DuplexChannelFactory<IPtlcWcfService>(this.m_instanceContext, tcpBinding);
            //this.m_wcfClient = this.m_duplexChannel.CreateChannel(new EndpointAddress(url));
            var client = new WcfServiceClient(new InstanceContext(new ServiceCallback()), tcpBinding, new EndpointAddress(url));

            //client.InnerDuplexChannel.Closed += (s, e) => m_isConnected = false;
            //client.InnerDuplexChannel.Faulted += (s, e) =>
            //{
            //    if (m_isConnected != false)
            //    {
            //        m_isConnected = false; this.OnServerConnectedChanged(new ServerConnectedChangedEventArgs(false, String.Empty));
            //    }
            //};
            m_wcfClient = client;
            Console.WriteLine("连接成功");
        }
    /// <summary>
    /// Handles the Click event of the btnGetAdTypes control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="System.EventArgs"/>
    /// instance containing the event data.</param>
    private void btnGetAdTypes_Click(object sender, EventArgs e) {
      IWcfService service = new WcfServiceClient();
      AdType[] adTypes = service.GetAdTypes();

      StringBuilder builder = new StringBuilder();
      foreach (AdType adType in adTypes) {
        builder.AppendFormat("Ad type name is '{0}' and id is {1}.\n", adType.idField,
            adType.nameField);
      }
      MessageBox.Show(builder.ToString());
    }
        public void Open(string host, int port)
        {
            var tmt = TimeSpan.FromSeconds(5);

            client = new WcfServiceClient(new BasicHttpBinding()
            {
                ReceiveTimeout = tmt, SendTimeout = tmt, OpenTimeout = tmt
            },
                                          new EndpointAddress($"http://{host}:{port}"));

            client.Open();
        }
Exemple #8
0
        public void DoTest()
        {
            Console.WriteLine("DoTest thread: {0}", Thread.CurrentThread.ManagedThreadId);
            client = WcfServiceClient <INameEntityService> .Create("test1");

            client.AsyncCompleted += new EventHandler <GenericAsyncCompletedEventArgs>(client1_AsynchCompleted);

            //client.AsyncBegin(client.Instance.GetAddress, null, 8);

            client.AsyncBegin("GetAddress", null, 8);
            client.AsyncBegin("DoSomethingElse", null, "comm");     //test a void return type
            client.AsyncBegin("DoNothing", null, null);             //test void return type with no params
        }
        public MainShopRepository(WcfServiceClient <IBeerData> clientProxyBeerData, WcfServiceClient <IBeerConfig> clientProxyBeerConfig)
        {
            if (clientProxyBeerData == null)
            {
                throw new ArgumentNullException(nameof(clientProxyBeerData));
            }
            if (clientProxyBeerConfig == null)
            {
                throw new ArgumentNullException(nameof(clientProxyBeerConfig));
            }

            _clientProxyBeerData   = clientProxyBeerData;
            _clientProxyBeerConfig = clientProxyBeerConfig;
        }
Exemple #10
0
        /// <summary>
        /// Handles the Click event of the btnGetAdTypes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/>
        /// instance containing the event data.</param>
        private void btnGetAdTypes_Click(object sender, EventArgs e)
        {
            IWcfService service = new WcfServiceClient();

            AdType[] adTypes = service.GetAdTypes();

            StringBuilder builder = new StringBuilder();

            foreach (AdType adType in adTypes)
            {
                builder.AppendFormat("Ad type name is '{0}' and id is {1}.\n", adType.nameField,
                                     adType.idField);
            }
            MessageBox.Show(builder.ToString());
        }
        /// <summary>
        /// Set the centralized Lucene engine as the search engine and initialize it
        /// using the provided WCF endpoint binding.
        /// </summary>
        public static IRepositoryBuilder UseLucene29CentralizedSearchEngineWithWcf(this IRepositoryBuilder repositoryBuilder,
                                                                                   Binding binding, EndpointAddress address)
        {
            if (binding == null)
            {
                throw new ArgumentNullException(nameof(binding));
            }
            if (address == null)
            {
                throw new ArgumentNullException(nameof(address));
            }

            WcfServiceClient.InitializeServiceEndpoint(binding, address);

            return(repositoryBuilder.UseLucene29CentralizedSearchEngine());
        }
Exemple #12
0
        private static void WaitForServiceStarted(Binding serviceBinding, EndpointAddress serviceEndpoint)
        {
            Console.WriteLine($"Is write.lock deleted? :)");

            while (true)
            {
                try
                {
                    using (var client = new WcfServiceClient(serviceBinding, serviceEndpoint))
                        client.Alive();
                    return;
                }
                catch (Exception e)
                {
                    Console.WriteLine($"Wait for service ({e.Message})");
                }

                Task.Delay(1000).ConfigureAwait(false).GetAwaiter().GetResult();
            }
        }
 public void DoTest()
 {
     using (var client1 = WcfServiceClient <INameEntityService> .Create("test1"))
     {
         try
         {
             int        type       = 0;
             NameEntity nameEntity = new NameEntity();
             bool       ret        = client1.Instance.CreateNameEntityByTypeByParam(type, ref nameEntity);
             Console.WriteLine("{0}", ret);
         }
         catch (FaultException <WcfServiceFault> fault)
         {
             Console.WriteLine(fault.ToString());
         }
         catch (Exception e) //handles exceptions not in wcf communication
         {
             Console.WriteLine(e.ToString());
         }
     }
 }
Exemple #14
0
        public async Task <IActionResult> Echo(string input)
        {
            var wcfClient = new WcfServiceClient();

            if (string.IsNullOrEmpty(input) || string.IsNullOrWhiteSpace(input))
            {
                input = "nothing set";
            }

            var output = "An error has occured \r\n";

            try
            {
                output = await wcfClient.EchoAsync(input);
            }
            catch (CommunicationException commsException)
            {
                if (Environment.IsDevelopment())
                {
                    output += $"The service is unreachable. The error from the exception is: {commsException.Message}";
                }
                else
                {
                    output += $"The service is unreachable.";
                }
            }
            catch (Exception e)
            {
                if (Environment.IsDevelopment())
                {
                    output += $"Some unexpected exception occured. The error message is: {e.Message}\r\n\r\n The stacktrace is:\r\n{e.StackTrace}";
                }
                else
                {
                    output += $"Some unexpected exception occured.";
                }
            }
            return(Ok(output));
        }
Exemple #15
0
        static void Main(string[] args)
        {
            WcfServiceClient client = new WcfServiceClient();

            client.ClientCredentials.UserName.UserName = "******";
            client.ClientCredentials.UserName.Password = "******";
            client.ClientCredentials.ServiceCertificate.Authentication.CertificateValidationMode
                = X509CertificateValidationMode.None;

            // Add the below only in DEV machines.
            // **** DO NOT ADD THIS IN PRODUCTION ****
            System.Net.ServicePointManager.ServerCertificateValidationCallback
                += delegate(object sender, X509Certificate certificate,
                            X509Chain chain, SslPolicyErrors errors)
                {
                return(true);
                };

            var response = client.GetRamdomGuid();

            Console.WriteLine(response);
        }
 public WcfServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) :
     base(WcfServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress)
 {
 }
Exemple #17
0
 private void button1_Click(object sender, EventArgs e)
 {
     WcfServiceClient client = new WcfServiceClient();
     MessageBox.Show(client.GetData(10, 15));
     client.Close();
 }
 public void DownloadViaWcf()
 {
     var client = new WcfServiceClient();
     client.DoWorkCompleted += ClientDoWorkCompleted;
     client.DoWorkAsync();
 }
Exemple #19
0
 public WcfProvider()
 {
     _senderProxy   = new WcfServiceClient("NetTcpBindingSender");
     _receiverProxy = new WcfServiceClient("NetTcpBindingReceiver");
 }
Exemple #20
0
        bool Login()
        {
            WcfServiceClient client;
            try
            {
                client = new WcfServiceClient();
                client.ClientCredentials.UserName.UserName = cbxUserName.Text;
                client.ClientCredentials.UserName.Password = txtPwd.Text;
                client.SayHello(cbxUserName.Text);
            }
            catch (Exception ex)
            {
                ControlsHelper.ShowErrorMessage("登陆失败", ex.InnerException.Message);
                return false;
            }

            try
            {
                string macAddress = NetHelper.GetMacAddress();
                string ipAddress = NetHelper.GetIPAddress();
                string hostName = NetHelper.GetHostName();
                SysUser user = client.Login(macAddress, ipAddress, hostName);
                Identity.CurrentUser = user;
                Identity.LoadFunctionInfo();
            }
            catch (Exception ex)
            {
                ControlsHelper.ShowErrorMessage("登陆失败", ex.Message);
                return false;
            }

            return true;
        }
 public WcfServiceClient(EndpointConfiguration endpointConfiguration) :
     base(WcfServiceClient.GetBindingForEndpoint(endpointConfiguration), WcfServiceClient.GetEndpointAddress(endpointConfiguration))
 {
 }