• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Description.ServiceMetadataBehavior类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.ServiceModel.Description.ServiceMetadataBehavior的典型用法代码示例。如果您正苦于以下问题:C# ServiceMetadataBehavior类的具体用法?C# ServiceMetadataBehavior怎么用?C# ServiceMetadataBehavior使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ServiceMetadataBehavior类属于System.ServiceModel.Description命名空间,在下文中一共展示了ServiceMetadataBehavior类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: StartService

        public void StartService()
        {
            StopService();
            Trace.WriteLine("create ServiceHost(typeof(Service1))");

            if (!__configureService)
                _serviceHost = new ServiceHost(typeof(Service1));
            else
            {
                _serviceHost = new ServiceHost(typeof(Service1), new Uri("http://localhost:8701/Test_wcf_service/"));

                WebHttpBinding webHttpBinding = new WebHttpBinding();
                webHttpBinding.CrossDomainScriptAccessEnabled = true;
                ServiceEndpoint serviceEndpoint = _serviceHost.AddServiceEndpoint(typeof(Service1), webHttpBinding, "service1");
                serviceEndpoint.Behaviors.Add(new WebHttpBehavior());
                //serviceEndpoint.Behaviors.Add(new CorsEnablingBehavior());

                ServiceMetadataBehavior serviceMetadataBehavior = new ServiceMetadataBehavior();
                serviceMetadataBehavior.HttpGetEnabled = true;
                serviceMetadataBehavior.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                _serviceHost.Description.Behaviors.Add(serviceMetadataBehavior);
            }

            if (__trace)
                TraceServiceDescription(_serviceHost.Description);

            Trace.WriteLine("open ServiceHost");
            _serviceHost.Open();
            Trace.WriteLine("service is started");
            Trace.WriteLine();
        }
开发者ID:labeuze,项目名称:source,代码行数:31,代码来源:ServiceHostManager.cs


示例2: Main

        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8000/GlydeServiceModelExamples/Service");

            ServiceHost selfHost = new ServiceHost(typeof(StringManipulatorService), baseAddress);

            try
            {
                selfHost.AddServiceEndpoint(
                    typeof(IStringManipulator),
                    new WSHttpBinding(),
                    "StringManipulatorService");

                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                selfHost.Description.Behaviors.Add(smb);

                // Step 5 of the hosting procedure: Start (and then stop) the service.
                selfHost.Open();
                Console.WriteLine("The service is ready.");
                Console.WriteLine("Press <ENTER> to terminate service.");
                Console.WriteLine();
                Console.ReadLine();

                // Close the ServiceHostBase to shutdown the service.
                selfHost.Close();

            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception occurred: {0}", ce.Message);
                selfHost.Abort();
            }
        }
开发者ID:danielglyde,项目名称:WCFStringManipulator,代码行数:34,代码来源:Program.cs


示例3: Main

	public static void Main ()
	{
		SymmetricSecurityBindingElement sbe =
			new SymmetricSecurityBindingElement ();
		sbe.ProtectionTokenParameters =
			new SslSecurityTokenParameters ();
		ServiceHost host = new ServiceHost (typeof (Foo));
		HttpTransportBindingElement hbe =
			new HttpTransportBindingElement ();
		CustomBinding binding = new CustomBinding (sbe, hbe);
		binding.ReceiveTimeout = TimeSpan.FromSeconds (5);
		host.AddServiceEndpoint ("IFoo",
			binding, new Uri ("http://localhost:8080"));
		ServiceCredentials cred = new ServiceCredentials ();
		cred.SecureConversationAuthentication.SecurityStateEncoder =
			new MyEncoder ();
		cred.ServiceCertificate.Certificate =
			new X509Certificate2 ("test.pfx", "mono");
		cred.ClientCertificate.Authentication.CertificateValidationMode =
			X509CertificateValidationMode.None;
		host.Description.Behaviors.Add (cred);
		host.Description.Behaviors.Find<ServiceDebugBehavior> ()
			.IncludeExceptionDetailInFaults = true;
//		foreach (ServiceEndpoint se in host.Description.Endpoints)
//			se.Behaviors.Add (new StdErrInspectionBehavior ());
		ServiceMetadataBehavior smb = new ServiceMetadataBehavior ();
		smb.HttpGetEnabled = true;
		smb.HttpGetUrl = new Uri ("http://localhost:8080/wsdl");
		host.Description.Behaviors.Add (smb);
		host.Open ();
		Console.WriteLine ("Hit [CR] key to close ...");
		Console.ReadLine ();
		host.Close ();
	}
开发者ID:alesliehughes,项目名称:olive,代码行数:34,代码来源:samplesvc10.cs


示例4: Main

        static void Main(string[] args)
        {
            string command;
            Uri baseAddress = new Uri("http://localhost:8000/wob/Login");
            ServiceHost selfHost = null;
            try
            {
                selfHost = new ServiceHost(typeof(LoginService), baseAddress);
                selfHost.AddServiceEndpoint(typeof(ILogin), new WSDualHttpBinding(), "LoginService");

                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                selfHost.Description.Behaviors.Add(smb);

                selfHost.Open();
                Console.WriteLine("Open");
                while (true)
                {
                    command = Console.ReadLine();
                    if (command == "e")
                        break;
                }
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("Failure!");
                Console.WriteLine(ce);
                Console.ReadLine();
                selfHost.Abort();
            }
        }
开发者ID:mcmonkey,项目名称:wob,代码行数:31,代码来源:WobConsoleProgram.cs


示例5: Main

        static void Main(string[] args)
        {
            Uri address = new Uri("http://localhost:8080/Lab2.Service.Age");
            ServiceHost serviceHost = new ServiceHost(typeof(Days), address);
            try
            {
                serviceHost.AddServiceEndpoint(typeof(IDays),
                    new WSHttpBinding(),
                    "Days");
                ServiceMetadataBehavior smBehavior = new ServiceMetadataBehavior();
                smBehavior.HttpGetEnabled = true;
                serviceHost.Description.Behaviors.Add(smBehavior);

                serviceHost.Open();
                Console.WriteLine("Tjänsten är öppen!");
                Console.WriteLine("Tryck enter för att avsluta");
                Console.ReadLine();
            }
            catch (CommunicationException ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
                throw;
            }
            finally
            {
                serviceHost.Close();
            }
        }
开发者ID:MartinaMagnusson,项目名称:WCF,代码行数:29,代码来源:Program.cs


示例6: Main

        static void Main(string[] args)
        {
            var baseAddress = new Uri("http://localhost:8080/Calculator");

            using (var host = new ServiceHost(typeof(Calculator), baseAddress))
            {
                host.AddServiceEndpoint(typeof(ICalculator), new BasicHttpBinding(), "Calculator");
                var serviceMetadataBehavior = new ServiceMetadataBehavior
                                                    {
                                                        HttpGetEnabled = true,
                                                        MetadataExporter =
                                                            {
                                                                PolicyVersion =
                                                                    PolicyVersion
                                                                    .Policy15
                                                            }
                                                    };
                host.Description.Behaviors.Add(serviceMetadataBehavior);

                host.Open();

                Console.WriteLine("The host is ready at: {0}", baseAddress);
                Console.WriteLine("Press <Enter> to stop the host");
                Console.ReadKey();

                host.Close();
            }
        }
开发者ID:modulexcite,项目名称:Tx,代码行数:28,代码来源:Program.cs


示例7: Main

        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8733/Design_Time_Addresses/GetDate/");

            ServiceHost selfHost = new ServiceHost(typeof(DateService), baseAddress);

            try
            {
                selfHost.AddServiceEndpoint(typeof(IDateService), new WSHttpBinding(), "Date Service");
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                selfHost.Description.Behaviors.Add(smb);

                using (selfHost)
                {
                    selfHost.Open();
                    Console.WriteLine("Service is ready\nPress any key  to exit");
                    Console.WriteLine();
                    Console.ReadKey();
                }
            }
            catch (CommunicationException ex)
            {
                Console.WriteLine("An exception occured: {0}", ex.Message);
                selfHost.Abort();
            }
        }
开发者ID:Dyno1990,项目名称:TelerikAcademy-1,代码行数:27,代码来源:Program.cs


示例8: Main

        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8080/hello");
            // Create the ServiceHost.
            using (ServiceHost host = new ServiceHost(typeof(Service1)))
            {
                // Enable metadata publishing.
                ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
                smb.HttpGetEnabled = true;
                smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                //host.Description.Behaviors.Add(smb);

                // Open the ServiceHost to start listening for messages. Since
                // no endpoints are explicitly configured, the runtime will create
                // one endpoint per base address for each service contract implemented
                // by the service.
                host.Open();

                host.Faulted += Host_Faulted;
                Console.WriteLine("The service is ready at {0}", baseAddress);
                Console.WriteLine("Press <Enter> to stop the service.");
                Console.ReadLine();

                // Close the ServiceHost.
                host.Close();
            }
        }
开发者ID:xsolon,项目名称:if,代码行数:27,代码来源:Program.cs


示例9: InitializeService

        public void InitializeService()
        {
            BasicHttpBinding libraryBinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
            libraryBinding.MaxReceivedMessageSize = 67108864;
            libraryServiceHost.AddServiceEndpoint(typeof(IMediaLibraryService),
                libraryBinding, string.Empty);

            BasicHttpBinding playbackBinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
            playbackBinding.MaxReceivedMessageSize = 67108864;
            playbackServiceHost.AddServiceEndpoint(typeof(IMediaPlaybackService),
                playbackBinding, string.Empty);

            ServiceMetadataBehavior libraryBehavior = new ServiceMetadataBehavior();
            libraryBehavior.HttpGetEnabled = true;
            libraryServiceHost.Description.Behaviors.Add(libraryBehavior);
            libraryServiceHost.AddServiceEndpoint(typeof(IMetadataExchange),
                MetadataExchangeBindings.CreateMexHttpBinding(), @"mex");

            ServiceMetadataBehavior playbackBehavior = new ServiceMetadataBehavior();
            playbackBehavior.HttpGetEnabled = true;
            playbackServiceHost.Description.Behaviors.Add(playbackBehavior);
            playbackServiceHost.AddServiceEndpoint(typeof(IMetadataExchange),
                MetadataExchangeBindings.CreateMexHttpBinding(), @"mex");

            libraryServiceHost.Open();
            playbackServiceHost.Open();
        }
开发者ID:garyjohnson,项目名称:Remotive,代码行数:27,代码来源:EndpointService.cs


示例10: Main

        static void Main(string[] args)
        {
            //BaseAddress
            var baseAddress = new Uri("http://localhost:8080/SelfService.NextThousand");
            //ServiceHost
            ServiceHost selfServiceHost = new ServiceHost(typeof(NextThousandCheckerService),baseAddress);
            try
            {
                //Abc - endpoint
                selfServiceHost.AddServiceEndpoint(typeof(INextThousand), new WSHttpBinding(),
                    "NextThousandCheckerService");
                //Metadata
                ServiceMetadataBehavior smBehavior = new ServiceMetadataBehavior { HttpGetEnabled = true };
                selfServiceHost.Description.Behaviors.Add(smBehavior);

                //startar tjänsten
                selfServiceHost.Open();
                Console.WriteLine("Tjänsten är öppen!");
                Console.ReadKey();
            }
            catch (CommunicationException ex)
            {
                Console.WriteLine($"Kommunikations fel{ex.Message}");
                selfServiceHost.Abort();
                Console.ReadKey();
                throw;
            }
        }
开发者ID:Emmyandersson,项目名称:WCF,代码行数:28,代码来源:Program.cs


示例11: Main

        static void Main(string[] args)
        {
            var baseAddress = new Uri("https://localhost:44355");

            using (var host = new ServiceHost(typeof(HelloWorldService), baseAddress))
            {
                var binding = new WSHttpBinding(SecurityMode.Transport);
                binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;

                host.Credentials.ServiceCertificate.SetCertificate(StoreLocation.LocalMachine, StoreName.My, X509FindType.FindBySubjectName, "localhost");
                host.Credentials.ClientCertificate.Authentication.RevocationMode = X509RevocationMode.NoCheck;
                host.Credentials.ClientCertificate.Authentication.TrustedStoreLocation = StoreLocation.LocalMachine;
                host.Credentials.ClientCertificate.Authentication.CertificateValidationMode = System.ServiceModel.Security.X509CertificateValidationMode.ChainTrust;

                var endpoint = typeof(IHelloWorldService);
                host.AddServiceEndpoint(endpoint, binding, baseAddress);

                var metaBehavior = new ServiceMetadataBehavior();
                metaBehavior.HttpGetEnabled = true;
                metaBehavior.HttpGetUrl = new Uri("http://localhost:9000/mex");
                metaBehavior.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                host.Description.Behaviors.Add(metaBehavior);

                host.Open();

                Console.WriteLine("Service is ready. Hit enter to stop service.");
                Console.ReadLine();

                host.Close();
            }
        }
开发者ID:DeanMaurer,项目名称:SampleTwoWayTLSWithCerts,代码行数:31,代码来源:Program.cs


示例12: Open

        public void Open()
        {
            urlservice = string.Format("http://{0}:{1}/{2}", channel.listener_host, channel.service_port - 1, channel._id);
            urlmeta = string.Format("http://{0}:{1}/{2}", channel.listener_host, channel.service_port, channel._id);
            host = new ServiceHost(new ChannelAPI(channel));
            host.Opening += new EventHandler(host_Opening);
            host.Opened += new EventHandler(host_Opened);
            host.Closing += new EventHandler(host_Closing);
            host.Closed += new EventHandler(host_Closed);

            BasicHttpBinding httpbinding = new BasicHttpBinding();
            httpbinding.Security.Mode = BasicHttpSecurityMode.None;
            host.AddServiceEndpoint(typeof(IChannelAPI), httpbinding, urlservice);
            //host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
            ServiceMetadataBehavior metaBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
            if (metaBehavior == null)
            {
                metaBehavior = new ServiceMetadataBehavior();
                metaBehavior.HttpGetUrl = new Uri(urlmeta);
                metaBehavior.HttpGetEnabled = true;
                host.Description.Behaviors.Add(metaBehavior);
            }
            Append(string.Format("{0} channel starting .....", channel._id));
            host.Open();
        }
开发者ID:GNCPay,项目名称:core,代码行数:25,代码来源:ServiceHostEnhanced.cs


示例13: StartService

        static void StartService()
        {
            var localV4Address = GetLocalV4Address();

            var localAddress = "http://" + localV4Address + ":8000/zpd";
            var baseAddress = new Uri(localAddress);
            var host = new ServiceHost(typeof(ZPDService), baseAddress);
            try
            {
                //host.AddServiceEndpoint(typeof(IZPDService), new WSHttpBinding(), "Service");
                var smb = new ServiceMetadataBehavior
                              {HttpGetEnabled = true, MetadataExporter = {PolicyVersion = PolicyVersion.Policy15}};
                host.Description.Behaviors.Add(smb);
                host.Open();
                Console.WriteLine("Service is ready at {0}. Press <ENTER> to terminate", localAddress);
                Console.ReadLine();
                host.Close();
                ZuneMediaPlayerManager.ClosePlayer();
            }
            catch (CommunicationException ce)
            {
                Console.WriteLine("An exception occurred: {0}", ce.Message);
                host.Abort();
            }

            Console.WriteLine("Press <ENTER> to close");
            Console.ReadLine();
        }
开发者ID:quad341,项目名称:zpd,代码行数:28,代码来源:Program.cs


示例14: ServiceFromCode

        static void ServiceFromCode()
        {
            Console.Out.WriteLine("Testing Udp From Code.");

            Binding datagramBinding = new CustomBinding(new BinaryMessageEncodingBindingElement(), new UdpTransportBindingElement());

            // using the 2-way calculator method requires a session since UDP is not inherently request-response
            SampleProfileUdpBinding calculatorBinding = new SampleProfileUdpBinding(true);
            calculatorBinding.ClientBaseAddress = new Uri("soap.udp://localhost:8003/");

            Uri calculatorAddress = new Uri("soap.udp://localhost:8001/");
            Uri datagramAddress = new Uri("soap.udp://localhost:8002/datagram");

            // we need an http base address so that svcutil can access our metadata
            ServiceHost service = new ServiceHost(typeof(CalculatorService), new Uri("http://localhost:8000/udpsample/"));
            ServiceMetadataBehavior metadataBehavior = new ServiceMetadataBehavior();
            metadataBehavior.HttpGetEnabled = true;
            service.Description.Behaviors.Add(metadataBehavior);
            service.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

            service.AddServiceEndpoint(typeof(ICalculatorContract), calculatorBinding, calculatorAddress);
            service.AddServiceEndpoint(typeof(IDatagramContract), datagramBinding, datagramAddress);
            service.Open();

            Console.WriteLine("Service is started from code...");
            Console.WriteLine("Press <ENTER> to terminate the service and start service from config...");
            Console.ReadLine();

            service.Close();
        }
开发者ID:spzenk,项目名称:sfdocsamples,代码行数:30,代码来源:UdpTestService.cs


示例15: btnStartStop_Click

 private void btnStartStop_Click(object sender, EventArgs e)
 {
     if (ServiceStarted)
     {
         host.Close();
         ServiceStarted = false;
         lblMessage.Text = "Service is not running!";
         btnStartStop.Text = "Start service";
     }
     else
     {
         using (host)
         {
             Uri baseAddress = new Uri(txtBaseLocation.Text);
             host = new ServiceHost(typeof(Service), baseAddress);
             ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
             behavior.HttpGetEnabled = true;
             host.Description.Behaviors.Add(behavior);
             host.AddServiceEndpoint(typeof(IService), new BasicHttpBinding(), "Service");
             if (chkShowMess.Checked)
             {
                 host.AddServiceEndpoint(typeof(IMetadataExchange), new BasicHttpBinding(), "MEX");
             }
             host.Open();
             lblMessage.Visible = true;
             lblMessage.Text = "Service is running!";
             ServiceStarted = true;
             btnStartStop.Text = "Stop service";
         }
     }
 }
开发者ID:bichhaithanhthien,项目名称:WCFGroupService,代码行数:31,代码来源:frmHost.cs


示例16: Uri

        Uri baseAddress { get; set; } = new Uri("http://localhost:8000/hello");//Uri("http://192.168.14.86:8000/hello");

        private void button1_Click(object sender, EventArgs e)
        {
            var baseAddress = new Uri("http://" + localHostIps.Text);// + ":/hello");

            host = new ServiceHost(typeof(VentsService), baseAddress);            

            var smb = new ServiceMetadataBehavior
            {
                HttpGetEnabled = true,
                MetadataExporter = { PolicyVersion = PolicyVersion.Policy15 }
            };
            host.Description.Behaviors.Add(smb);

            try
            {
                host.Open();
                Status.Text = $"The service is ready at {baseAddress}";
                button1.Enabled = false;
                button2.Enabled = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                
            }

        }
开发者ID:GitHubVents,项目名称:AirVentsCad,代码行数:29,代码来源:Form1.cs


示例17: BtStartServiceClick

        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);
                host.AddServiceEndpoint(contractType, new WSDualHttpBinding(), "");
                if (cbMex.Checked)
                {
                    host.AddServiceEndpoint(typeof(IMetadataExchange), new WSDualHttpBinding(), "MEX");
                }
                host.Open();
                lbmessage.Visible = true;
                lbmessage.Text = "Host Option is running...";
                //MessageBox.Show(" " + svcEndpoint.Address);
                ServiceStarted = true;

            }
        }
开发者ID:pippopboy,项目名称:ChatApplication,代码行数:29,代码来源:Form1.cs


示例18: Main

        static void Main(string[] args)
        {
            var baseAddress = new Uri(string.Format("http://localhost:11001/mixedservice/{0}/", Guid.NewGuid().ToString()));

            using (var host = new ServiceHost(typeof(MixedService), baseAddress))
            {
                host.Opened += (sender, e) =>
                {
                    host.Description.Endpoints.All((ep) =>
                    {
                        Console.WriteLine(ep.Contract.Name + ": " + ep.ListenUri);
                        return true;
                    });
                };

                var serviceMetadataBehavior = new ServiceMetadataBehavior();
                serviceMetadataBehavior.HttpGetEnabled = true;
                serviceMetadataBehavior.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
                host.Description.Behaviors.Add(serviceMetadataBehavior);

                host.AddServiceEndpoint(typeof(IStringService), new BasicHttpBinding(), "string");
                host.AddServiceEndpoint(typeof(ICalculateService), new BasicHttpBinding(), "calculate");
                host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");

                host.Open();

                Console.WriteLine("Press any key to exit.");
                Console.ReadKey();
            }
        }
开发者ID:shaunxu,项目名称:phare,代码行数:30,代码来源:Program.cs


示例19: Main

        static void Main(string[] args)
        {
            ServiceHost MathServiceHost = null;
            try
            {
                //Base Address for MathService
                Uri httpBaseAddress = new Uri("http://localhost:8090/MathService/Calculator");
                Uri tcpBaseAddress = new Uri("net.tcp://localhost:8081/MathService/Calculator");
                
                //Instantiate ServiceHost
                MathServiceHost = new ServiceHost(typeof(MathService.Calculator), httpBaseAddress);
 
                //Add Endpoint to Host
                MathServiceHost.AddServiceEndpoint(typeof(MathService.ICalculator), new WSHttpBinding(), "");            
 
                //Metadata Exchange
                ServiceMetadataBehavior serviceBehavior = new ServiceMetadataBehavior();
                serviceBehavior.HttpGetEnabled = true;
                MathServiceHost.Description.Behaviors.Add(serviceBehavior);

                //Open
                MathServiceHost.Open();
                Console.WriteLine("Service is live now at : {0}", httpBaseAddress);
                Console.ReadKey();                
            }

            catch (Exception ex)
            {
                MathServiceHost = null;
                Console.WriteLine("There is an issue with MathService" + ex.Message);
            }
        }
开发者ID:chungvodim,项目名称:HelloWCF,代码行数:32,代码来源:Program.cs


示例20: Main

        static void Main(string[] args)
        {
            Uri baseAddress = new Uri("http://localhost:8290/MyAgeService");

            using (var selfServiceHost = new ServiceHost(typeof(MyAgeService), baseAddress))
            {
                try
                {

                    selfServiceHost.AddServiceEndpoint(typeof(IMyAgeService), new WSHttpBinding(), "MyAgeService");

                    ServiceMetadataBehavior smBehavior = new ServiceMetadataBehavior();
                    smBehavior.HttpGetEnabled = true;
                    selfServiceHost.Description.Behaviors.Add(smBehavior);

                    selfServiceHost.Open();
                    Console.WriteLine("Tjänsten är ööppppeennnnn!");
                    Console.WriteLine("Tryck ENTER för att avsluta selfservice");
                    Console.ReadLine();
                }
                catch (CommunicationException ex)
                {
                    Console.WriteLine($"Ett kommunikationsfel har inträffat! {ex.Message}");
                    selfServiceHost.Abort();
                    Console.ReadLine();
                    throw;
                }
            }
        }
开发者ID:JHNWLL,项目名称:WCF-labbar,代码行数:29,代码来源:Program.cs



注:本文中的System.ServiceModel.Description.ServiceMetadataBehavior类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Description.WebHttpBehavior类代码示例发布时间:2022-05-26
下一篇:
C# Description.ServiceEndpoint类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap