Beispiel #1
0
        public async void ConnectToClient(string hostName, int port, string playerName,  Color color)
        {
            var binding = new WSDualHttpBinding(WSDualHttpSecurityMode.None);
            binding.ReceiveTimeout = TimeSpan.FromSeconds(30);
            binding.SendTimeout = TimeSpan.FromSeconds(30);

            //TODO: Wire up the callbackHandler...

            _client = new GameServiceClient(
                new InstanceContext(_callbackHandler), 
                binding,
                new EndpointAddress(String.Format("http://{0}:{1}/GameService", hostName, port)));
            _client.Open();

            //Just calling join here locks up...
            PlayerId = await _client.JoinAsync(new Player
            {
                Name = playerName,
                Color = new Service.Contracts.Color 
                {
                    A = color.A,
                    R = color.R,
                    G = color.G,
                    B = color.B
                }
            });

            //TODO: Remove this once the view goes somewhere else...
            MessageBox.Show(String.Format("Player: {0} joined with id: {1}", playerName, PlayerId));
        }
Beispiel #2
0
        public SQLWebServiceModel(MessageCredentialType MessageCredentialType, string ServiceURL)
        {
            this.ServiceURL = ServiceURL;

            WSDualHttpBinding binding = new WSDualHttpBinding(WSDualHttpSecurityMode.Message);
            //끝점
            EndpointAddress EndpointURL = new EndpointAddress
                (
                new Uri(this.ServiceURL)
                );

            //보안설정
            binding.Security.Message.ClientCredentialType = MessageCredentialType;
            WebServiceChannel = new ChannelFactory<IWebService>
                (
                    new ServiceEndpoint
                        (
                        ContractDescription.GetContract(typeof(IWebService)),
                        binding,
                        EndpointURL
                        )
                );
            //인증서 유효성 검사 안하게 한다
            WebServiceChannel.Credentials.ServiceCertificate.Authentication.CertificateValidationMode =
                X509CertificateValidationMode.None;
        }
Beispiel #3
0
        private static void Main()
        {
            //You need admin permissions to listen on a port,
            //run visual studio as an admin if you wish to
            //run/debug this from within visual studio
            var binding = new WSDualHttpBinding();
            binding.ReceiveTimeout = TimeSpan.FromSeconds(5);
            binding.SendTimeout = TimeSpan.FromSeconds(5);
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            binding.Security.Mode = WSDualHttpSecurityMode.None;

            var baseAddress = new Uri("http://localhost:4050/");
            var serviceAddress = new Uri("http://localhost:4050/GameService");
            var metadataBehavior = new ServiceMetadataBehavior();
            metadataBehavior.HttpGetEnabled = true;

            // Create a ServiceHost for the GameService type and provide the base address.
            using (var serviceHost = new ServiceHost(typeof (GameService), baseAddress))
            {
                serviceHost.AddServiceEndpoint(typeof (IGameService), binding, serviceAddress);
                serviceHost.Description.Behaviors.Add(metadataBehavior);

                // Open the ServiceHostBase to create listeners and start listening for messages.
                serviceHost.Open();

                // The service can now be accessed.
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();

                // Close the ServiceHostBase to shutdown the service.
                serviceHost.Close();
            }
        }
 public static Object GetWcfReference(Type type, object[] info)
 {
   if (info.Length == 2)
     info = new object[] { info[0], null, info[1] };
   if (info.Length != 3)
     return null;
   Type genType;
   Type factType;
   if (info[0] == null)
   {
     genType = typeof(ChannelFactory<>);
     factType = genType.MakeGenericType(new Type[] { type });
     if (info[1] == null)
       info[1] = new WSHttpBinding();
     info = new object[] { info[1], new EndpointAddress((string)info[2]) };
   }
   else
   {
     genType = typeof(DuplexChannelFactory<>);
     factType = genType.MakeGenericType(new Type[] { type });
     info[0] = new InstanceContext(info[0]);
     info[2] = new EndpointAddress((string)info[2]);
     if (info[1] == null)
       info[1] = new WSDualHttpBinding();
   }
   object factObject = Activator.CreateInstance(factType, info);
   MethodInfo methodInfo = factType.GetMethod("CreateChannel", new Type[] { });
   return methodInfo.Invoke(factObject, null);
 }
        public static Binding CreateBinding(string bindingName)
        {
            Binding result = null;

            try
            {
                if (string.Compare(bindingName, typeof(WSHttpBinding).FullName, true) == 0)
                {
                    result = new WSHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(WS2007HttpBinding).FullName, true) == 0)
                {
                    result = new WS2007HttpBinding();
                }
                else if (string.Compare(bindingName, typeof(BasicHttpBinding).FullName, true) == 0)
                {
                    result = new BasicHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(WSDualHttpBinding).FullName, true) == 0)
                {
                    result = new WSDualHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(WS2007FederationHttpBinding).FullName, true) == 0)
                {
                    result = new WS2007FederationHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(WSFederationHttpBinding).FullName, true) == 0)
                {
                    result = new WSFederationHttpBinding();
                }
                else if (string.Compare(bindingName, typeof(NetNamedPipeBinding).FullName, true) == 0)
                {
                    result = new NetNamedPipeBinding();
                }
                else if (string.Compare(bindingName, typeof(NetMsmqBinding).FullName, true) == 0)
                {
                    result = new NetMsmqBinding();
                }
                else if (string.Compare(bindingName, typeof(MsmqIntegrationBinding).FullName, true) == 0)
                {
                    result = new MsmqIntegrationBinding();
                }
                else if (string.Compare(bindingName, typeof(NetTcpBinding).FullName, true) == 0)
                {
                    result = new NetTcpBinding();
                }
                else if (string.Compare(bindingName, typeof(NetPeerTcpBinding).FullName, true) == 0)
                {
                    result = new NetPeerTcpBinding();
                }
            }
            catch
            {
                result = new BasicHttpBinding(BasicHttpSecurityMode.None);
            }

            return result;
        }
 private ServiceHost SetupService() {
     var myBinding = new WSDualHttpBinding { Security = new WSDualHttpSecurity { Mode = WSDualHttpSecurityMode.None } };
     // Create a ServiceHost for the CalculatorService type and provide the base address.
     var serviceHost = new ServiceHost(typeof(PubSubService));
     serviceHost.AddServiceEndpoint(typeof(IPubSubService), myBinding, "http://localhost:8733/Service/PubSubService");
     PubSubService.AddImportEvent += (o, id) => AddImport(id);
     serviceHost.Open();
     return serviceHost;
 }
Beispiel #7
0
 /*
  * private static function to create channel for hosting root server. 
  * @param url specifies the url on which the rootserver is to be hosted.
  * @returns ServiceHost is returned 
  */
 static ServiceHost CreateChannel(string url)
 {
   WSDualHttpBinding binding = new WSDualHttpBinding();
   Uri address = new Uri(url);
   Type service = typeof(RootServer);
   ServiceHost rootHost = new ServiceHost(service, address);
   rootHost.AddServiceEndpoint(typeof(IRootServer), binding, address);
   return rootHost;
 }
Beispiel #8
0
 static IRootServer createProxy(string url)
 {
   WSDualHttpBinding binding = new WSDualHttpBinding();
   EndpointAddress address = new EndpointAddress(url);
   IRootServerCallback callBack = new MockCallBackHandler();
   InstanceContext instanceContext = new InstanceContext(callBack);
   DuplexChannelFactory<IRootServer> factory = new DuplexChannelFactory<IRootServer>(instanceContext, binding, address);
   return factory.CreateChannel();
 }
 public static WSDualHttpBinding CreateDualHttpBinding()
 {
     WSDualHttpBinding binding = new WSDualHttpBinding()
     {
         CloseTimeout = TimeSpan.FromMinutes(10),
         OpenTimeout = TimeSpan.FromMinutes(10),
         ReceiveTimeout = TimeSpan.FromMinutes(10),
         SendTimeout = TimeSpan.FromMinutes(10),
     };
     return binding;
 }
        public static ILocationService GetProxy(string myuri)
        {
            if (_channelFactory == null)
            {
                var wsDualHttpBinding = new WSDualHttpBinding();
                wsDualHttpBinding.ClientBaseAddress = new Uri(myuri);

                _channelFactory = new ChannelFactory<ILocationService>(wsDualHttpBinding,
                                                                       Properties.Settings.Default.Url_service);
            }
            return (_channelFactory.CreateChannel());
        }
 public static Binding Resolve(WcfBindingTypes type)
 {
     Binding binding = null;
     switch (type)
     {
         case WcfBindingTypes.BasicHttpBinding:
             binding = new BasicHttpBinding();
             break;
         case WcfBindingTypes.NetTcpBinding:
             binding = new NetTcpBinding();
             break;
         case WcfBindingTypes.NetTcpContextBinding:
             binding = new NetTcpContextBinding();
             break;
         case WcfBindingTypes.WsHttpBinding:
             binding = new WSHttpBinding();
             break;
         case WcfBindingTypes.NetMsmqBinding:
             binding = new NetMsmqBinding();
             break;
         case WcfBindingTypes.NetPeerTcpBinding:
             binding = new NetPeerTcpBinding();
             break;
         case WcfBindingTypes.BasicHttpContextBinding:
             binding = new BasicHttpContextBinding();
             break;
         case WcfBindingTypes.WSHttpContextBinding:
             binding = new WSHttpContextBinding();
             break;
         case WcfBindingTypes.WS2007FederationHttpBinding:
             binding = new WS2007FederationHttpBinding();
             break;
         case WcfBindingTypes.WS2007HttpBinding:
             binding = new WS2007HttpBinding();
             break;
         case WcfBindingTypes.NetNamedPipeBinding:
             binding = new NetNamedPipeBinding();
             break;
         case WcfBindingTypes.WSFederationHttpBinding:
             binding = new WSFederationHttpBinding();
             break;
         case WcfBindingTypes.WSDualHttpBinding:
             binding = new WSDualHttpBinding();
             break;
         default:
             binding = new CustomBinding();
             break;
     }
     return binding;
 }
        private async static void DuplexSample()
        {
            var binding = new WSDualHttpBinding();
            var address =
                  new EndpointAddress("http://localhost:8733/Design_Time_Addresses/MessageService/Service1/");

            var clientCallback = new ClientCallback();
            var context = new InstanceContext(clientCallback);

            var factory = new DuplexChannelFactory<IMyMessage>(context, binding, address);

            IMyMessage messageChannel = factory.CreateChannel();

            await Task.Run(() => messageChannel.MessageToServer("From the server"));
        }
 public static ServiceHost CreateServiceHost(string baseAddr, Object serviceObj, string[] endpointAddrs, Type[] serviceTypes, bool[] haveCallbacks)
 {
   ServiceHost ret = null;
   ret = new ServiceHost(serviceObj, new Uri(baseAddr));
   for (int i = 0;i<serviceTypes.Length;i++)
   {
     System.ServiceModel.Channels.Binding binding;
     if (haveCallbacks[i])
       binding = new WSDualHttpBinding();
     else
       binding = new WSHttpBinding();
     ret.AddServiceEndpoint(serviceTypes[i], binding, baseAddr+endpointAddrs[i]);
   }
   return ret;
 }
Beispiel #14
0
    static void Main(string[] args)
    {
      string url = "http://localhost:8080/DIDemo";
      WSDualHttpSecurityMode securityMode = WSDualHttpSecurityMode.Message;
      WSDualHttpBinding binding = new WSDualHttpBinding(securityMode);
      Uri baseAddress = new Uri(url);
      Type service = typeof(WcfService);
      ServiceHost host = new ServiceHost(service, baseAddress);
      host.AddServiceEndpoint(typeof(IService), binding, baseAddress);

      host.Open();
      Console.WriteLine("Server started");
      
      Console.ReadKey();
      host.Close();
    }
        public IReaderService InitService(string endpoint)
        {
            var myBinding = new WSDualHttpBinding();

            myBinding.ReceiveTimeout = new TimeSpan(0, 0, 50);
            myBinding.SendTimeout = new TimeSpan(0, 0, 50);

            //myBinding.MaxReceivedMessageSize = long.MaxValue;
            myBinding.MaxBufferPoolSize = long.MaxValue;

            myBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;
            myBinding.ReaderQuotas.MaxDepth = int.MaxValue;
            myBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            myBinding.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
            myBinding.ReaderQuotas.MaxNameTableCharCount = int.MaxValue;

            //TODO : read this url from app cpnfig.
            //var myEndpoint = new EndpointAddress("http://localhost:8733/ReaderService/");
            var myEndpoint = new EndpointAddress(endpoint);
            var myChannelFactory = new ChannelFactory<IReaderService>(myBinding, myEndpoint);

            IReaderService client = null;

            try
            {
                client = myChannelFactory.CreateChannel();

                //This will invoke InitService fxn at ReaderService.
                string ver = client.GetVersion();

                //--- *This code will be at form closing (at the end of clientApp lifecycle).
                //((ICommunicationObject)client).Close();
            }
            catch (Exception ex)
            {
                Console.WriteLine("Failed to ger version. Error - " + ex.ToString());
                if (client != null)
                {
                    ((ICommunicationObject)client).Abort();
                }
            }

            return client;
        }
        public void StartHost(int port)
        {
            var binding = new WSDualHttpBinding();
            binding.ReceiveTimeout = TimeSpan.FromSeconds(5);
            binding.SendTimeout = TimeSpan.FromSeconds(5);
            binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
            binding.Security.Mode = WSDualHttpSecurityMode.None;

            var baseAddress = new Uri(String.Format("http://localhost:{0}/", port));
            var serviceAddress = new Uri(String.Format("http://localhost:{0}/GameService", port));
            var metadataBehavior = new ServiceMetadataBehavior();
            metadataBehavior.HttpGetEnabled = true;

            // Create a ServiceHost for the GameService type and provide the base address.
            _serviceHost = new ServiceHost(typeof(Service.GameService), baseAddress);
            _serviceHost.AddServiceEndpoint(typeof(Service.IGameService), binding, serviceAddress);
            _serviceHost.Description.Behaviors.Add(metadataBehavior);

            // Open the ServiceHostBase to create listeners and start listening for messages.
            _serviceHost.Open();
        }
Beispiel #17
0
        public bool Subscribe(string name)
        {
            if (producers.ContainsKey(name))
                return false;

            var binding = new WSDualHttpBinding();
            binding.SendTimeout = TimeSpan.FromSeconds(10.0);
            var client = new BondDataService.ProducerClient(context, binding, new EndpointAddress(uri));
            if (!producers.TryAdd(name, client))
                return false;
            try
            {
                producers[name].Subscribe(name);
            }
            catch
            {
                return false;
            }

            return true;
        }
Beispiel #18
0
        static void Main(string[] args)
        {
            var baseAddress = new Uri("http://localhost:8733/server/subscriber/");
            using (var host = new ServiceHost(typeof(TimedConcurrentQueueSubscriber), baseAddress))
            {
                var serviceMetaDataBehavior = new ServiceMetadataBehavior
                {
                    HttpGetEnabled = true,
                    HttpsGetEnabled = true
                };
                host.Description.Behaviors.Add(serviceMetaDataBehavior);

                var serviceDebugBehavior = new ServiceDebugBehavior
                {
                    IncludeExceptionDetailInFaults = true
                };
                if (host.Description.Behaviors.Find<ServiceDebugBehavior>() == null)
                    host.Description.Behaviors.Add(serviceDebugBehavior);

                var duplexBinding = new WSDualHttpBinding
                {
                    ClientBaseAddress = new Uri("http://localhost:8734/client/dispatcher"),
                    MaxBufferPoolSize = 5242880,
                    MaxReceivedMessageSize = 6553600
                };
                var serviceEndpoint = new ServiceEndpoint(
                    ContractDescription.GetContract(typeof(Subscriber)),
                    duplexBinding, new EndpointAddress(baseAddress));
                host.Description.Endpoints.Add(serviceEndpoint);

                host.Open();

                Console.WriteLine($"{nameof(Subscriber)} service listening on {baseAddress}");
                Console.WriteLine("Press any key to exit....");
                Console.ReadKey(true);

                host.Close();
            }
        }
Beispiel #19
0
 static void Main(string[] args)
 {
     //Let user input port, so multiple chat clients can run on same machine.
     int port = 12001;
     if (args.Length < 1)
     {
         Console.WriteLine("Enter port number");
         port = int.Parse(Console.ReadLine());
     }
     else
     {
         port = int.Parse(args[0]);
     }
     var instanceContext = new InstanceContext(new ChatCallbackHandler());
     var binding = new WSDualHttpBinding();
     binding.ClientBaseAddress = new Uri(string.Format("http://localhost:{0}/ChatClient",port));
     var endpoint = new EndpointAddress("http://localhost:12000/ChatServer");
     //using(var client = new ChatService.ChatServiceClient(instanceContext,binding, endpoint)) //Visual Studio generated client proxy.
     using(var factory = new DuplexChannelFactory<Contract.IChatService>(instanceContext, binding, endpoint)) //Channelfactory create by hand.
     {
         var client = factory.CreateChannel();
         try
         {
             //client.Open();
             client.Register();
             Console.WriteLine("Chat client ready running on " + binding.ClientBaseAddress);
             do
             {
                 var message = Console.ReadLine();
                 client.Send(message);
             } while (true);
         } catch(Exception ex)
         {
             Console.Write(ex.ToString());
         }
     }
     Console.ReadKey();
 }
        private void BtStartServiceClick(object sender, EventArgs e)
        {
            if (ServiceStarted)
            {
                host.Close();
                ServiceStarted = false;
            }
            else
            {

                baseAddress = new Uri(txbaseaddress.Text);
                host = new ServiceHost(instanceType, baseAddress);
                ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
                behavior.HttpGetEnabled = true;
                host.Description.Behaviors.Add(behavior);
                WSDualHttpBinding ws = new WSDualHttpBinding();
                ws.MaxBufferPoolSize = int.MaxValue;
                ws.MaxReceivedMessageSize = int.MaxValue;
                ws.ReaderQuotas.MaxArrayLength = int.MaxValue;
                ws.ReaderQuotas.MaxBytesPerRead = int.MaxValue;
                ws.ReaderQuotas.MaxStringContentLength = int.MaxValue;

                host.AddServiceEndpoint(contractType, ws, "");
                //host.AddServiceEndpoint(contractType, new NetMsmqBinding(), "");

                if (cbMex.Checked)
                {
                    host.AddServiceEndpoint(typeof(IMetadataExchange), ws, "MEX");
                }
                host.Open();
                lbmessage.Visible = true;
                lbmessage.Text = "Host Option is running...";
                //MessageBox.Show(" " + svcEndpoint.Address);
                ServiceStarted = true;

            }
        }
Beispiel #21
0
        static void Main(string[] args)
        {
            // Create the ServiceHost.
            using (ServiceHost host = new ServiceHost(typeof(Producer), new Uri(uri)))
            {
                var binding = new WSDualHttpBinding();
                binding.SendTimeout = TimeSpan.FromSeconds(3.0);
                host.AddServiceEndpoint(typeof(IProducer), binding, uri);

                // Enable metadata publishing.
                var smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                host.Description.Behaviors.Add(smb);

                host.Open();
                
                Console.WriteLine("Press <Enter> to stop the service...");
                Console.ReadLine();
                Console.WriteLine("Closing...");

                host.Close();
            }
        }
        private void btn_Author_WsDualHttp_Click(object sender, EventArgs e)
        {
            try
            {
                address = new EndpointAddress("http://localhost:" + txtLLocaWsDualHttp.Text + "/GetMark_Service");
                WSDualHttpBinding binding = new WSDualHttpBinding();

                proxy = ChannelFactory<IService>.CreateChannel(binding, address);
                lstMem = proxy.GetAuthors();
                grid_WsHttp.DataSource = lstMem;
            }
            catch (CommunicationException commProblem) //lỗi giao tiếp với server
            {
                MessageBox.Show("There was a communication problem. " + commProblem.Message + commProblem.StackTrace);
            }
        }
        private void openChannel()
        {
            if (channelOpen == false || channelFactory.State != CommunicationState.Opened)
            {
                // WCF
                WSDualHttpBinding binding = new WSDualHttpBinding();
                binding.MaxReceivedMessageSize = int.MaxValue;
                binding.ClientBaseAddress = Service.GetCallbackAddress(this.URL);

                EndpointAddress endpoint = new EndpointAddress(this.URL);
                channelFactory = new DuplexChannelFactory<IService>(this, binding, endpoint);
                channelFactory.Faulted += channelFactory_Faulted;
                channelFactory.Closed += channelFactory_Closed;

                channel = channelFactory.CreateChannel();

                channelOpen = false;
            }
        }
Beispiel #24
0
        public override bool RegisterUser(UserNodeCore context, User user,
            string serviceNodeAddress, string callbackAddress)
        {
            try
            {
                ClientCallback callback = new ClientCallback(context);

                // First of all, set up the connection
                EndpointAddress endPointAddress = new EndpointAddress(serviceNodeAddress);
                WSDualHttpBinding binding = new WSDualHttpBinding();
                binding.ClientBaseAddress = new Uri(callbackAddress);
                DuplexChannelFactory<IDarPooling> factory = new DuplexChannelFactory<IDarPooling>(
                        callback, binding, endPointAddress);
                context.ServiceProxy = factory.CreateChannel();
            }
            catch
            {
                context.ServiceProxy = null;
                return false;
            }

            Command c = new Communication.RegisterUserCommand(user);

            try
            {
                context.ServiceProxy.HandleDarPoolingRequest(c);
            }
            catch (TimeoutException e)
            {
                context.ServiceProxy = null;
                throw e;
            }
            return true;
        }
Beispiel #25
0
        public override bool Join(UserNodeCore context, string username, string password,
            string serviceNodeAddress, string callbackAddress)
        {
            try
            {
                ClientCallback callback = new ClientCallback(context);

                // First of all, set up the connection
                EndpointAddress endPointAddress = new EndpointAddress(serviceNodeAddress);
                WSDualHttpBinding binding = new WSDualHttpBinding();
                binding.ClientBaseAddress = new Uri(callbackAddress);
                DuplexChannelFactory<IDarPooling> factory = new DuplexChannelFactory<IDarPooling>(
                        callback, binding, endPointAddress);
                context.ServiceProxy = factory.CreateChannel();
            }
            catch
            {
                context.ServiceProxy = null;
                return false;
            }

            // Now, hopefully you have a working ServiceProxy.
            string passwordHash = Communication.Tools.HashString(password);
            Command c = new JoinCommand(context.UserNode, username, passwordHash);

            try
            {
                context.ServiceProxy.HandleDarPoolingRequest(c);
            }
            catch (TimeoutException e)
            {
                context.ServiceProxy = null;
                throw e;
            }

            // Finally, if Join is NOT successfull, remove reference (UserNodeCore.onResultReceive)
            return true;
        }
        public static void TestCommands(Command c)
        {
            string serviceNodeAddress = "http://localhost:1111/Catania";
            string callbackAddress = "http://localhost:2222/prova";

            ClientCallback callback = new ClientCallback();

            // First of all, set up the connection
            EndpointAddress endPointAddress = new EndpointAddress(serviceNodeAddress);
            WSDualHttpBinding binding = new WSDualHttpBinding();
            binding.ClientBaseAddress = new Uri(callbackAddress);
            DuplexChannelFactory<IDarPooling> factory = new DuplexChannelFactory<IDarPooling>(
                    callback, binding, endPointAddress);

            IDarPooling serviceProxy = factory.CreateChannel();

            serviceProxy.HandleDarPoolingRequest(c);
        }
Beispiel #27
0
        /// <summary>
        /// 绑定的协议
        /// </summary>
        /// <param name="strBindingName">strBindingName</param>
        /// <returns>Binding</returns>
        public static Binding WCfBindingName(string strBindingName)
        {
            switch (strBindingName.ToUpper())
            {
                case "WSHTTPBINDING":
                    WSHttpBinding wsbinding = new WSHttpBinding();
                    wsbinding.MaxReceivedMessageSize = 4048000;
                    wsbinding.MaxBufferPoolSize = 1048576;
                    wsbinding.ReaderQuotas.MaxStringContentLength = 4048000;
                    wsbinding.ReaderQuotas.MaxArrayLength = 4048000;
                    wsbinding.ReaderQuotas.MaxBytesPerRead = 4048000;
                    wsbinding.SendTimeout = new TimeSpan(0, 3, 0);
                    return wsbinding;
                case "WSDUALHTTPBINDING":
                    WSDualHttpBinding wsdbinding = new WSDualHttpBinding();
                    wsdbinding.MaxReceivedMessageSize = 4048000;
                    wsdbinding.MaxBufferPoolSize = 1048576;
                    wsdbinding.ReaderQuotas.MaxStringContentLength = 4048000;
                    wsdbinding.ReaderQuotas.MaxArrayLength = 4048000;
                    wsdbinding.ReaderQuotas.MaxBytesPerRead = 4048000;
                    wsdbinding.SendTimeout = new TimeSpan(0, 3, 0);
                    return wsdbinding;
                case "WSFEDERATIONHTTPBINDING":
                    WSFederationHttpBinding wsfe = new WSFederationHttpBinding();
                    wsfe.MaxReceivedMessageSize = 4048000;
                    wsfe.MaxBufferPoolSize = 1048576;
                    wsfe.ReaderQuotas.MaxStringContentLength = 4048000;
                    wsfe.ReaderQuotas.MaxArrayLength = 4048000;
                    wsfe.ReaderQuotas.MaxBytesPerRead = 4048000;
                    wsfe.SendTimeout = new TimeSpan(0, 3, 0);
                    return wsfe;
                case "NETTCPBINDING":
                    NetTcpBinding netTcpBinding = new NetTcpBinding();
                    netTcpBinding.MaxReceivedMessageSize = 4048000;
                    netTcpBinding.MaxBufferPoolSize = 1048576;
                    netTcpBinding.ReaderQuotas.MaxStringContentLength = 4048000;
                    return netTcpBinding;
                case "NETNAMEDPIPEBINDING":

                    NetNamedPipeBinding netNamePipeBinding = new NetNamedPipeBinding();
                    netNamePipeBinding.MaxReceivedMessageSize = 4048000;
                    netNamePipeBinding.MaxBufferPoolSize = 1048576;
                    netNamePipeBinding.ReaderQuotas.MaxStringContentLength = 4048000;
                    return netNamePipeBinding;
                case "NETMSMQBINDING":
                    return new NetMsmqBinding();
                case "NETPEERTCPBINDING":
                    return new NetPeerTcpBinding();
                case "CUSTOMBINDING":
                    BinaryMessageEncodingBindingElement encodingBindingElement = new BinaryMessageEncodingBindingElement();
                    encodingBindingElement.ReaderQuotas.MaxStringContentLength = 4048000;
                    HttpTransportBindingElement transportBindingElement = new HttpTransportBindingElement();
                    transportBindingElement.MaxReceivedMessageSize = 4048000;
                    transportBindingElement.MaxBufferSize = 4048000;
                    transportBindingElement.MaxBufferPoolSize = 4048000;
                    CustomBinding customBinding = new CustomBinding(encodingBindingElement, transportBindingElement);
                    customBinding.SendTimeout = new TimeSpan(0, 3, 0);
                    return customBinding;
                default:
                    BasicHttpBinding binding = new BasicHttpBinding();
                    binding.MaxReceivedMessageSize = 4048000;
                    binding.MaxBufferSize = 4048000;
                    binding.MaxBufferPoolSize = 1048576;
                    binding.ReaderQuotas.MaxStringContentLength = 4048000;
                    binding.ReaderQuotas.MaxArrayLength = 4048000;
                    binding.ReaderQuotas.MaxBytesPerRead = 4048000;
                    binding.SendTimeout = new TimeSpan(0, 3, 0);
                    return binding;
            }
        }
 internal static bool TryCreate(BindingElementCollection elements, out Binding binding)
 {
     WSDualHttpSecurity security;
     binding = null;
     if (elements.Count > 7)
     {
         return false;
     }
     SecurityBindingElement securityElement = null;
     HttpTransportBindingElement transport = null;
     MessageEncodingBindingElement encoding = null;
     TransactionFlowBindingElement txFlow = null;
     ReliableSessionBindingElement session = null;
     CompositeDuplexBindingElement compositeDuplex = null;
     OneWayBindingElement oneWay = null;
     foreach (BindingElement element8 in elements)
     {
         if (element8 is SecurityBindingElement)
         {
             securityElement = element8 as SecurityBindingElement;
         }
         else if (element8 is TransportBindingElement)
         {
             transport = element8 as HttpTransportBindingElement;
         }
         else if (element8 is MessageEncodingBindingElement)
         {
             encoding = element8 as MessageEncodingBindingElement;
         }
         else if (element8 is TransactionFlowBindingElement)
         {
             txFlow = element8 as TransactionFlowBindingElement;
         }
         else if (element8 is ReliableSessionBindingElement)
         {
             session = element8 as ReliableSessionBindingElement;
         }
         else if (element8 is CompositeDuplexBindingElement)
         {
             compositeDuplex = element8 as CompositeDuplexBindingElement;
         }
         else if (element8 is OneWayBindingElement)
         {
             oneWay = element8 as OneWayBindingElement;
         }
         else
         {
             return false;
         }
     }
     if (transport == null)
     {
         return false;
     }
     if (encoding == null)
     {
         return false;
     }
     if (!encoding.CheckEncodingVersion(System.ServiceModel.EnvelopeVersion.Soap12))
     {
         return false;
     }
     if (compositeDuplex == null)
     {
         return false;
     }
     if (oneWay == null)
     {
         return false;
     }
     if (session == null)
     {
         return false;
     }
     if (txFlow == null)
     {
         txFlow = GetDefaultTransactionFlowBindingElement();
     }
     if (!TryCreateSecurity(securityElement, out security))
     {
         return false;
     }
     WSDualHttpBinding binding2 = new WSDualHttpBinding(transport, encoding, txFlow, session, compositeDuplex, oneWay, security);
     if (!binding2.IsBindingElementsMatch(transport, encoding, txFlow, session, compositeDuplex, oneWay))
     {
         return false;
     }
     binding = binding2;
     return true;
 }
Beispiel #29
0
        /// <summary>
        /// Creates a <see cref="Binding"/> based on the specified <paramref name="address"/>.
        /// </summary>
        /// <param name="address">The URI that is used to determine the type of <see cref="Binding"/> to be created.</param>
        /// <param name="enableSecurity">A boolean value that indicated whether security is to be enabled on the <see cref="Binding"/>.</param>
        /// <returns>An <see cref="Binding"/> object if a valid <paramref name="address"/> is specified; otherwise null.</returns>
        /// <remarks>
        /// This list shows all valid address schemes that can be specified in the <paramref name="address"/>:
        /// <list type="table">
        ///     <listheader>
        ///         <term>Address Scheme</term>
        ///         <description>Usage</description>
        ///     </listheader>
        ///     <item>
        ///         <term><b>http://</b> or <b>http.soap11://</b></term>
        ///         <description>An <paramref name="address"/> of <b>http.soap11://localhost:2929</b> will create an <see cref="BasicHttpBinding"/> and update the <paramref name="address"/> to <b>http://localhost:2929</b>.</description>
        ///     </item>
        ///     <item>
        ///         <term><b>http.soap12://</b></term>
        ///         <description>An <paramref name="address"/> of <b>http.soap12://localhost:2929</b> will create an <see cref="WSHttpBinding"/> and update the <paramref name="address"/> to <b>http://localhost:2929</b>.</description>
        ///     </item>
        ///     <item>
        ///         <term><b>http.duplex://</b></term>
        ///         <description>An <paramref name="address"/> of <b>http.duplex://localhost:2929</b> will create an <see cref="WSDualHttpBinding"/> and update the <paramref name="address"/> to <b>http://localhost:2929</b>.</description>
        ///     </item>
        ///     <item>
        ///         <term><b>http.rest://</b></term>
        ///         <description>An <paramref name="address"/> of <b>http.rest://localhost:2929</b> will create an <see cref="WebHttpBinding"/> and update the <paramref name="address"/> to <b>http://localhost:2929</b>.</description>
        ///     </item>
        ///     <item>
        ///         <term><b>net.tcp://</b></term>
        ///         <description>An <paramref name="address"/> of <b>net.tcp://localhost:2929</b> will create an <see cref="NetTcpBinding"/> and leave the <paramref name="address"/> unchanged.</description>
        ///     </item>
        ///     <item>
        ///         <term><b>net.p2p://</b></term>
        ///         <description>An <paramref name="address"/> of <b>net.p2p://localhost:2929</b> will create an <see cref="NetPeerTcpBinding"/> and leave the <paramref name="address"/> unchanged.</description>
        ///     </item>
        ///     <item>
        ///         <term><b>net.pipe://</b></term>
        ///         <description>An <paramref name="address"/> of <b>net.pipe://localhost:2929</b> will create an <see cref="NetNamedPipeBinding"/> and leave the <paramref name="address"/> unchanged.</description>
        ///     </item>
        ///     <item>
        ///         <term><b>net.msmq://</b></term>
        ///         <description>An <paramref name="address"/> of <b>net.msmq://localhost:2929</b> will create an <see cref="NetMsmqBinding"/> and leave the <paramref name="address"/> unchanged.</description>
        ///     </item>
        /// </list>
        /// <para>
        /// The <paramref name="enableSecurity"/> parameter value is ignored Mono deployments since security bindings are not implemented.
        /// </para>
        /// </remarks>
        public static Binding CreateServiceBinding(ref string address, bool enableSecurity)
        {
            address = address.Trim();
            if (string.IsNullOrEmpty(address))
                return null;

            int index = address.IndexOf("://");
            string scheme = address.Substring(0, index >= 0 ? index : address.Length);
            switch (scheme.ToLower())
            {
                case "http":
                case "http.soap11":
                    // Format address.
                    address = address.Replace("http.soap11", "http");
                    // Create binding.
                    BasicHttpBinding soap11Binding = new BasicHttpBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        soap11Binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
                        soap11Binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                    }
                    else
                    {
                        // Disable security.
                        soap11Binding.Security.Mode = BasicHttpSecurityMode.None;
                        soap11Binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                    }
#endif

                    return soap11Binding;
                case "http.soap12":
                    // Format address.
                    address = address.Replace("http.soap12", "http");
                    // Create binding.
                    WSHttpBinding soap12Binding = new WSHttpBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        soap12Binding.Security.Mode = SecurityMode.Transport;
                        soap12Binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                    }
                    else
                    {
                        // Disable security.
                        soap12Binding.Security.Mode = SecurityMode.None;
                        soap12Binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                    }
#endif

                    return soap12Binding;
                case "http.duplex":
                    // Format address.
                    address = address.Replace("http.duplex", "http");
                    // Create binding.
                    WSDualHttpBinding duplexBinding = new WSDualHttpBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        duplexBinding.Security.Mode = WSDualHttpSecurityMode.Message;
                    }
                    else
                    {
                        // Disable security.
                        duplexBinding.Security.Mode = WSDualHttpSecurityMode.None;
                    }
#endif

                    return duplexBinding;
                case "http.rest":
                    // Format address.
                    address = address.Replace("http.rest", "http");
                    // Create binding.
                    WebHttpBinding restBinding = new WebHttpBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        restBinding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly;
                        restBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
                    }
                    else
                    {
                        // Disable security.
                        restBinding.Security.Mode = WebHttpSecurityMode.None;
                        restBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
                    }
#endif

                    return restBinding;
                case "net.tcp":
                    // Create binding.
                    NetTcpBinding tcpBinding = new NetTcpBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        tcpBinding.Security.Mode = SecurityMode.Transport;
                        tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
                    }
                    else
                    {
                        // Disable sercurity.
                        tcpBinding.Security.Mode = SecurityMode.None;
                        tcpBinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.None;
                    }
#endif

                    return tcpBinding;
                case "net.p2p":
                    // Create binding.
#pragma warning disable 612, 618
                    NetPeerTcpBinding p2pBinding = new NetPeerTcpBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        p2pBinding.Security.Mode = SecurityMode.Transport;
                    }
                    else
                    {
                        // Disable security.
                        p2pBinding.Security.Mode = SecurityMode.None;
                    }
#endif

                    return p2pBinding;
                case "net.pipe":
                    // Create binding.
                    NetNamedPipeBinding pipeBinding = new NetNamedPipeBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        pipeBinding.Security.Mode = NetNamedPipeSecurityMode.Transport;
                    }
                    else
                    {
                        // Disable security.
                        pipeBinding.Security.Mode = NetNamedPipeSecurityMode.None;
                    }
#endif

                    return pipeBinding;
                case "net.msmq":
                    // Create binding.
                    NetMsmqBinding msmqBinding = new NetMsmqBinding();

#if !MONO
                    if (enableSecurity)
                    {
                        // Enable security.
                        msmqBinding.Security.Mode = NetMsmqSecurityMode.Transport;
                    }
                    else
                    {
                        // Disable security.
                        msmqBinding.Security.Mode = NetMsmqSecurityMode.None;
                    }
#endif

                    return msmqBinding;
                default:
                    return null;
            }
        }
Beispiel #30
0
        public Form1()
        {
            InitializeComponent();

            try
            {
                newsControl = new List<Control>();
                analysisControl = new List<Control>();

                EndpointAddress stockPriceAddress = new EndpointAddress("http://localhost:90/StockPrice");
                EndpointAddress stockNewsAddress = new EndpointAddress("http://localhost:90/StockNews");
                EndpointAddress stockFinanceAddress = new EndpointAddress("http://localhost:90/StockFinance");
                EndpointAddress stockForecastAddress = new EndpointAddress("http://localhost:90/StockForecast");

                BasicHttpBinding stockPriceBinding = new BasicHttpBinding();
                BasicHttpBinding stockNewsBinding = new BasicHttpBinding();
                WSDualHttpBinding stockForecastBinding = new WSDualHttpBinding();
                stockForecastBinding.ClientBaseAddress = new Uri("http://localhost:90/");

                stockPriceProxy = ChannelFactory<IStockPrice>.CreateChannel(stockPriceBinding, stockPriceAddress);
                stockNewsProxy = ChannelFactory<IStockNews>.CreateChannel(stockNewsBinding, stockNewsAddress);
                stockFinanceProxy = ChannelFactory<IFinancialIndicatorService>.CreateChannel(new BasicHttpBinding(), stockFinanceAddress);

                InstanceContext insContext = new InstanceContext(this);
                stockForecastProxy = new ForecastServiceClient(insContext, stockForecastBinding, stockForecastAddress);

                List<string[]> mostIncrease = stockPriceProxy.GetMostIncrease();
                List<string[]> mostDecrease = stockPriceProxy.GetMostDecrease();
                List<string[]> mostTraded = stockPriceProxy.GetMostTraded();

                DataTable mostIncreaseSource = ToDataTable(mostIncrease, new string[] { "Stock", "Open", "High", "Low", "Close", "Volume", "Change(%)" }, new int[] { 1, 3, 4, 5, 6, 7, 8 });
                DataTable mostDecreaseSource = ToDataTable(mostDecrease, new string[] { "Stock", "Open", "High", "Low", "Close", "Volume", "Change(%)" }, new int[] { 1, 3, 4, 5, 6, 7, 8 });
                DataTable mostTradedSource = ToDataTable(mostTraded, new string[] { "Stock", "Open", "High", "Low", "Close", "Volume" }, 5);

                dgvMostIncrease.DataSource = mostIncreaseSource;
                dgvMostDecrease.DataSource = mostDecreaseSource;
                dgvMostTraded.DataSource = mostTradedSource;

                int colCount = dgvMostIncrease.Columns.Count;
                int colWidth = (dgvMostIncrease.Width - 41) / 7;

                AutoSizeColumns(dgvMostIncrease, new int[] { 69, 69, 69, 69, 69, 69, 68 });
                AutoSizeColumns(dgvMostDecrease, new int[] { 69, 69, 69, 69, 69, 69, 68 });
                AutoSizeColumns(dgvMostTraded, new int[] { 80, 80, 80, 80, 81, 81 });

                AddNews(stockNewsProxy.GetNews("", Convert.ToInt32(txtViewCount.Value)));
                AddAnalysis(stockNewsProxy.GetExpertAnalysis("", Convert.ToInt32(txtAnalysisCount.Value)));

                List<string[]> periodsList = stockFinanceProxy.GetPeriods("HNM");
                foreach (string[] period in periodsList)
                {
                    string result = "Q" + period[0] + "/" + period[1];
                    cbbQuarter.Items.Add(result);
                }
                cbbQuarter.SelectedIndex = cbbQuarter.Items.Count - 1;

                cbbForecastsNum.SelectedIndex = cbbForecastsNum.Items.Count - 1;
            }
            catch (Exception e)
            {
                MessageBox.Show("Error connecting to service. Press OK to quit");
                Environment.Exit(-1);
            }
        }