本文整理匯總了C#中System.ServiceModel.Description.ServiceMetadataBehavior類的典型用法代碼示例。如果您正苦於以下問題:C# ServiceMetadataBehavior類的具體用法?C# ServiceMetadataBehavior怎麽用?C# ServiceMetadataBehavior使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ServiceMetadataBehavior類屬於System.ServiceModel.Description命名空間,在下文中一共展示了ServiceMetadataBehavior類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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();
}
示例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();
}
}
示例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 ();
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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;
}
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}
示例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";
}
}
}