Ejemplo n.º 1
0
        /// <summary>
        /// Shows the service.
        /// </summary>
        /// <param name="serviceInfo">The service info.</param>
        public void ShowService(ServiceInfoWrapper serviceInfo)
        {
            var fieldInfo = typeof(ServiceHost).GetField("serviceType", BindingFlags.Instance | BindingFlags.NonPublic);
            if (fieldInfo != null)
            {
                var serviceType = fieldInfo.GetValue(serviceInfo.Host) as Type;
                if (serviceType == null) return;

                var interfaces = serviceType.GetInterfaces();
                if (interfaces.Length < 1) return;
                var serviceInterface = interfaces[0];

                Text = serviceInterface.Name + " - WCF Service Test Harness";
            }

            var protocol = Protocol.NetTcp;
            switch (serviceInfo.Protocol.ToLower())
            {
                case "basic http":
                case "basichttp":
                    protocol = Protocol.BasicHttp;
                    Text = Text.Replace(" - WCF Service Test Harness", " - Basic HTTP - WCF Service Test Harness");
                    break;
                case "ws http":
                case "wshttp":
                    protocol = Protocol.WsHttp;
                    Text = Text.Replace(" - WCF Service Test Harness", " - WsHTTP - WCF Service Test Harness");
                    break;
                case "in process":
                case "inprocess":
                    protocol = Protocol.InProcess;
                    Text = Text.Replace(" - WCF Service Test Harness", " - In Process - WCF Service Test Harness");
                    break;
                case "rest http (xml)":
                    protocol = Protocol.RestHttpXml;
                    Text = Text.Replace(" - WCF Service Test Harness", " - REST XML - WCF Service Test Harness");
                    break;
                case "rest http (json)":
                    protocol = Protocol.RestHttpJson;
                    Text = Text.Replace(" - WCF Service Test Harness", " - REST JSON - WCF Service Test Harness");
                    break;
                case "net.tcp":
                case "nettcp":
                    Text = Text.Replace(" - WCF Service Test Harness", " - TCP/IP - WCF Service Test Harness");
                    break;
            }

            var size = MessageSize.Medium;
            switch (serviceInfo.MessageSize.ToLower())
            {
                case "normal":
                    size = MessageSize.Normal;
                    break;
                case "large":
                    size = MessageSize.Large;
                    break;
            }

            _ui.ShowService(serviceInfo.Host, serviceInfo.Port, string.Empty, protocol, size, new Uri(serviceInfo.Url));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds the service info.
        /// </summary>
        /// <param name="serviceType">Type of the service.</param>
        /// <param name="contractType">Type of the contract.</param>
        /// <param name="url">The URL.</param>
        /// <param name="binding">The binding.</param>
        /// <param name="host">The actual service host</param>
        private void AddServiceInfo(Type serviceType, Type contractType, string url, string binding, ServiceHost host)
        {
            if (contractType == null)
            {
                var interfaces = serviceType.GetInterfaces();
                contractType = interfaces.Length == 1 ? interfaces[0] : serviceType;
            }

            var uri  = !string.IsNullOrEmpty(url) ? new Uri(url) : null;
            var port = uri != null ? uri.Port : 0;
            var info = new ServiceInfoWrapper
            {
                ServiceContract = contractType,
                ServiceType     = serviceType,
                Url             = url,
                Host            = host,
                Protocol        = binding,
                WsdlExposed     = "No",
                Port            = port
            };

            long messageSize = 0;

            if (host != null)
            {
                foreach (var dispatcher in host.ChannelDispatchers)
                {
                    var listener = dispatcher.Listener;
                    if (listener != null)
                    {
                        var listenerType = listener.GetType();

                        var propertyInfo = listenerType.GetProperty("MaxReceivedMessageSize", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                        if (propertyInfo != null)
                        {
                            messageSize = Math.Max((long)propertyInfo.GetValue(listener, null), messageSize);
                            if (messageSize < 1024 * 1024 * 10)
                            {
                                info.MessageSize = "Normal";
                            }
                            else if (messageSize >= 1024 * 1024 * 100)
                            {
                                info.MessageSize = "Large";
                            }
                            else
                            {
                                info.MessageSize = "Medium";
                            }
                        }

                        var propertyInfo2 = listenerType.GetProperty("Uri", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                        if (propertyInfo2 != null)
                        {
                            var listenerUri = propertyInfo2.GetValue(listener, null) as Uri;
                            if (listenerUri != null)
                            {
                                if (listenerUri.AbsoluteUri.ToLower().EndsWith("/wsdl"))
                                {
                                    info.WsdlExposed = "Yes";
                                }
                            }
                        }
                    }
                }
            }

            var item = new ListViewItem(new[] { contractType.Name + " (" + serviceType.Name + ")", (!string.IsNullOrEmpty(url) ? "Started" : "Failed"), url, binding, info.MessageSize, info.WsdlExposed })
            {
                Tag = info
            };

            switch (binding.ToLower())
            {
            case "rest http (xml)":
                item.ImageIndex = 2;
                break;

            case "rest http (json)":
            case "http-get":
                item.ImageIndex = 1;
                break;

            case "basic http":
            case "ws http":
                item.ImageIndex = 3;
                break;

            case "net.tcp":
                item.ImageIndex = 0;
                break;

            default:
                item.ImageIndex = 0;
                break;
            }

            if (string.IsNullOrEmpty(url))
            {
                item.ForeColor = Color.Red;
            }

            listView1.Items.Add(item);
            listView1.Sort();
        }
        /// <summary>
        /// Shows the service.
        /// </summary>
        /// <param name="serviceInfo">The service info.</param>
        public void ShowService(ServiceInfoWrapper serviceInfo)
        {
            var fieldInfo = typeof(ServiceHost).GetField("serviceType", BindingFlags.Instance | BindingFlags.NonPublic);

            if (fieldInfo != null)
            {
                var serviceType = fieldInfo.GetValue(serviceInfo.Host) as Type;
                if (serviceType == null)
                {
                    return;
                }

                var interfaces = serviceType.GetInterfaces();
                if (interfaces.Length < 1)
                {
                    return;
                }
                var serviceInterface = interfaces[0];

                Text = serviceInterface.Name + " - WCF Service Test Harness";
            }

            var protocol = Protocol.NetTcp;

            switch (serviceInfo.Protocol.ToLower())
            {
            case "basic http":
            case "basichttp":
                protocol = Protocol.BasicHttp;
                Text     = Text.Replace(" - WCF Service Test Harness", " - Basic HTTP - WCF Service Test Harness");
                break;

            case "ws http":
            case "wshttp":
                protocol = Protocol.WsHttp;
                Text     = Text.Replace(" - WCF Service Test Harness", " - WsHTTP - WCF Service Test Harness");
                break;

            case "in process":
            case "inprocess":
                protocol = Protocol.InProcess;
                Text     = Text.Replace(" - WCF Service Test Harness", " - In Process - WCF Service Test Harness");
                break;

            case "rest http (xml)":
                protocol = Protocol.RestHttpXml;
                Text     = Text.Replace(" - WCF Service Test Harness", " - REST XML - WCF Service Test Harness");
                break;

            case "rest http (json)":
                protocol = Protocol.RestHttpJson;
                Text     = Text.Replace(" - WCF Service Test Harness", " - REST JSON - WCF Service Test Harness");
                break;

            case "net.tcp":
            case "nettcp":
                Text = Text.Replace(" - WCF Service Test Harness", " - TCP/IP - WCF Service Test Harness");
                break;
            }

            var size = MessageSize.Medium;

            switch (serviceInfo.MessageSize.ToLower())
            {
            case "normal":
                size = MessageSize.Normal;
                break;

            case "large":
                size = MessageSize.Large;
                break;
            }

            _ui.ShowService(serviceInfo.Host, serviceInfo.Port, string.Empty, protocol, size, new Uri(serviceInfo.Url));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Adds the service info.
        /// </summary>
        /// <param name="serviceType">Type of the service.</param>
        /// <param name="contractType">Type of the contract.</param>
        /// <param name="url">The URL.</param>
        /// <param name="binding">The binding.</param>
        /// <param name="host">The actual service host</param>
        private void AddServiceInfo(Type serviceType, Type contractType, string url, string binding, ServiceHost host)
        {
            if (contractType == null)
            {
                var interfaces = serviceType.GetInterfaces();
                contractType = interfaces.Length == 1 ? interfaces[0] : serviceType;
            }

            var uri = !string.IsNullOrEmpty(url) ? new Uri(url) : null;
            var port = uri != null ? uri.Port : 0;
            var info = new ServiceInfoWrapper
            {
                ServiceContract = contractType,
                ServiceType = serviceType,
                Url = url,
                Host = host,
                Protocol = binding,
                WsdlExposed = "No",
                Port = port
            };

            long messageSize = 0;
            if (host != null)
                foreach (var dispatcher in host.ChannelDispatchers)
                {
                    var listener = dispatcher.Listener;
                    if (listener != null)
                    {
                        var listenerType = listener.GetType();

                        var propertyInfo = listenerType.GetProperty("MaxReceivedMessageSize", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                        if (propertyInfo != null)
                        {
                            messageSize = Math.Max((long) propertyInfo.GetValue(listener, null), messageSize);
                            if (messageSize < 1024*1024*10) info.MessageSize = "Normal";
                            else if (messageSize >= 1024*1024*100) info.MessageSize = "Large";
                            else info.MessageSize = "Medium";
                        }

                        var propertyInfo2 = listenerType.GetProperty("Uri", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                        if (propertyInfo2 != null)
                        {
                            var listenerUri = propertyInfo2.GetValue(listener, null) as Uri;
                            if (listenerUri != null) if (listenerUri.AbsoluteUri.ToLower().EndsWith("/wsdl")) info.WsdlExposed = "Yes";
                        }
                    }
                }

            var item = new ListViewItem(new[] {contractType.Name + " (" + serviceType.Name + ")", (!string.IsNullOrEmpty(url) ? "Started" : "Failed"), url, binding, info.MessageSize, info.WsdlExposed}) {Tag = info};
            switch (binding.ToLower())
            {
                case "rest http (xml)":
                    item.ImageIndex = 2;
                    break;
                case "rest http (json)":
                case "http-get":
                    item.ImageIndex = 1;
                    break;
                case "basic http":
                case "ws http":
                    item.ImageIndex = 3;
                    break;
                case "net.tcp":
                    item.ImageIndex = 0;
                    break;
                default:
                    item.ImageIndex = 0;
                    break;
            }

            if (string.IsNullOrEmpty(url))
                item.ForeColor = Color.Red;

            listView1.Items.Add(item);
            listView1.Sort();
        }