本文整理汇总了C#中System.ServiceModel.ServiceHost.AddServiceEndpoint方法的典型用法代码示例。如果您正苦于以下问题:C# ServiceHost.AddServiceEndpoint方法的具体用法?C# ServiceHost.AddServiceEndpoint怎么用?C# ServiceHost.AddServiceEndpoint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.ServiceHost
的用法示例。
在下文中一共展示了ServiceHost.AddServiceEndpoint方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Run
public static void Run()
{
// Open post as non-admin:
// http://msdn.microsoft.com/en-us/library/ms733768.aspx
// netsh http add urlacl url=http://+:9999/ user='PROVCON-FAUST\martin'
var host = new ServiceHost (typeof (Server));
AddMexEndpoint (host);
host.AddServiceEndpoint (
typeof (IMyService), new BasicHttpBinding (),
new Uri ("http://provcon-faust:9999/service/"));
host.AddServiceEndpoint (
typeof (IMyService), new BasicHttpBinding (BasicHttpSecurityMode.Transport),
new Uri ("https://provcon-faust:9998/secureservice/"));
AddNetTcp (host);
AddNetTcp2 (host);
host.Open ();
foreach (var endpoint in host.Description.Endpoints)
Console.WriteLine (endpoint.Address);
Console.WriteLine ("Service running.");
Console.ReadLine ();
host.Close ();
}
示例2: StartStopService
public void StartStopService()
{
var baseUri = new Uri("http://localhost:8080/MyWebPage.WCF_Lab2");
var selfServiceHost = new ServiceHost(typeof(MyWebPageEntryPoint), baseUri);
using (selfServiceHost)
{
selfServiceHost.AddServiceEndpoint(typeof(ICalculateAge),
new WSHttpBinding(),
"CalculateAgeService");
selfServiceHost.AddServiceEndpoint(typeof(ICalculateBmi),
new WSHttpBinding(),
"CalculateBmiService");
selfServiceHost.AddServiceEndpoint(typeof(ICalculateEvenBirthday),
new WSHttpBinding(),
"CalculateEvenBirthdayService");
selfServiceHost.AddServiceEndpoint(typeof(ICalculateCalories),
new WSHttpBinding(),
"CalculateCaloriesBurned");
var smBehavior = new ServiceMetadataBehavior { HttpGetEnabled = true };
selfServiceHost.Description.Behaviors.Add(smBehavior);
selfServiceHost.Open();
Console.WriteLine($"Service opened: {DateTime.Now} at: {baseUri}");
Console.WriteLine("Press enter to shut down selfservice.");
Console.ReadKey();
}
}
示例3: Main
static void Main()
{
// только не null, ибо возникнет исключение
//var baseAddress = new Uri("http://localhost:8002/MyService");
var host = new ServiceHost(typeof(MyContractClient));//, baseAddress);
host.Open();
//var otherBaseAddress = new Uri("http://localhost:8001/");
var otherHost = new ServiceHost(typeof(MyOtherContractClient));//, otherBaseAddress);
var wsBinding = new BasicHttpBinding();
var tcpBinding = new NetTcpBinding();
otherHost.AddServiceEndpoint(typeof(IMyOtherContract), wsBinding, "http://localhost:8001/MyOtherService");
otherHost.AddServiceEndpoint(typeof(IMyOtherContract), tcpBinding, "net.tcp://localhost:8003/MyOtherService");
//AddHttpGetMetadata(otherHost);
AddMexEndpointMetadata(otherHost);
otherHost.Open();
// you can access http://localhost:8002/MyService
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Host());
otherHost.Close();
host.Close();
// you can not access http://localhost:8002/MyService
}
示例4: 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();
}
示例5: 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();
}
}
示例6: StartService
public void StartService()
{
Uri baseAddress = new Uri("http://localhost:8001/MarkManagementService");
Type contractType = typeof(IService);
Type instanceType = typeof(OperationService);
host = new ServiceHost(instanceType, baseAddress);
// Create basicHttpBinding endpoint at http://localhost:8001/OperationService
string relativeAddress = "OperationService";
host.AddServiceEndpoint(contractType, new BasicHttpBinding(), relativeAddress);
NetTcpBinding A = new NetTcpBinding(SecurityMode.Transport);
host.AddServiceEndpoint(contractType, new NetTcpBinding(), "net.tcp://localhost:9000/MarkManagementService");
host.AddServiceEndpoint(contractType, A, "net.tcp://localhost:9001/MarkManagementService");
// Add behavior for our MEX endpoint
//Add Mex endpoint can dung de khi client discovery thay duoc service
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetEnabled = true;
host.Description.Behaviors.Add(behavior);
// Add MEX endpoint at http://localhost:8000/MEX/
host.AddServiceEndpoint(typeof(IMetadataExchange), new BasicHttpBinding(), "MEX");
host.Open();
lbl_mess.Text = "Service is starting";
lbl_mess.ForeColor = Color.Green;
}
示例7: HostDiscoveryEndpoint
private static ServiceHost HostDiscoveryEndpoint(string hostName)
{
// Create a new ServiceHost with a singleton ChatDiscovery Proxy
ServiceHost myProxyHost = new
ServiceHost(new ChatDiscoveryProxy());
string proxyAddress = "net.tcp://" +
hostName + ":8001/discoveryproxy";
// Create the discovery endpoint
DiscoveryEndpoint discoveryEndpoint =
new DiscoveryEndpoint(
new NetTcpBinding(),
new EndpointAddress(proxyAddress));
discoveryEndpoint.IsSystemEndpoint = false;
// Add UDP Annoucement endpoint
myProxyHost.AddServiceEndpoint(new UdpAnnouncementEndpoint());
// Add the discovery endpoint
myProxyHost.AddServiceEndpoint(discoveryEndpoint);
myProxyHost.Open();
Console.WriteLine("Discovery Proxy {0}",
proxyAddress);
return myProxyHost;
}
示例8: Main
static void Main(string[] args)
{
// string address = "http://localhost:23456/TrustedServer/";
if(args==null || args.Count() <1 )
{
Usage();
return;
}
string address = args[0];
BasicHttpBinding binding = new BasicHttpBinding();
ServiceHost host = new ServiceHost(typeof(MetaDataServer), new Uri(address));
host.AddServiceEndpoint(typeof(IMetaDataService), binding, address);
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
// host.AddDefaultEndpoints();
MetaDataServer.initializeFromFile();
host.Open();
Console.WriteLine("Host is {0}. Press enter to close.", host.State);
Console.ReadLine();
MetaDataServer.writeToFile();
host.Close();
}
示例9: BuildHost
private ServiceHost BuildHost( IWcfServiceConfiguration configuration )
{
var serviceUri = configuration.Address;
var host = new ServiceHost( configuration.ServiceType, new Uri( ServerConfiguration.BaseAddress ) );
host.AddServiceEndpoint(
configuration.ContractType,
configuration.Binding,
serviceUri );
if ( configuration.EnableHttpMetadataExchange )
{
var mexUriString =
"{0}/{1}".AsFormat( configuration.MetadataExchangeUri ?? ServerConfiguration.BaseAddress,
configuration.Address );
host.Description.Behaviors.Add(
new ServiceMetadataBehavior
{
HttpGetEnabled = true,
HttpGetUrl = new Uri( mexUriString )
} );
host.AddServiceEndpoint( typeof( IMetadataExchange ), configuration.Binding, "mex" );
}
host.CloseTimeout = TimeSpan.FromMilliseconds( configuration.Timeout );
return host;
}
示例10: Main
static void Main(string[] args)
{
//ServiceHost myHost = new ServiceHost(typeof(WCFService));
ServiceHost myHost = new ServiceHost(typeof(WCFService),
new Uri("http://localhost:9003/AI3"),
new Uri("net.tcp://localhost:9004/AI4"));
myHost.AddDefaultEndpoints();
myHost.AddServiceEndpoint(typeof(IWCFService), new BasicHttpBinding(), "http://localhost:9001/AI");
myHost.AddServiceEndpoint(typeof(IWCFService), new NetTcpBinding(), "net.tcp://localhost:9002/");
ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
behavior.HttpGetUrl = new Uri("http://localhost:8090/WCFService");
behavior.HttpGetEnabled = true;
myHost.Description.Behaviors.Add(behavior);
try
{
myHost.Open();
Console.WriteLine("Service is worked ! Status : " + myHost.State);
foreach (ServiceEndpoint ep in myHost.Description.Endpoints)
{
Console.WriteLine("A : {0} - B : {1} - C : {2}", ep.Address, ep.Binding.Name, ep.Contract.Name);
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
Console.ReadLine();
}
示例11: Main
static void Main(string[] args)
{
string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
host.AddServiceEndpoint(typeof(ITestService), new BasicHttpBinding(), "soap");
WebHttpBinding webBinding = new WebHttpBinding();
webBinding.ContentTypeMapper = new MyRawMapper();
host.AddServiceEndpoint(typeof(ITestService), webBinding, "json").Behaviors.Add(new NewtonsoftJsonBehavior());
Console.WriteLine("Opening the host");
host.Open();
ChannelFactory<ITestService> factory = new ChannelFactory<ITestService>(new BasicHttpBinding(), new EndpointAddress(baseAddress + "/soap"));
ITestService proxy = factory.CreateChannel();
Console.WriteLine(proxy.GetPerson());
SendRequest(baseAddress + "/json/GetPerson", "GET", null, null);
SendRequest(baseAddress + "/json/EchoPet", "POST", "application/json", "{\"Name\":\"Fido\",\"Color\":\"Black and white\",\"Markings\":\"None\",\"Id\":1}");
SendRequest(baseAddress + "/json/Add", "POST", "application/json", "{\"x\":111,\"z\":null,\"w\":[1,2],\"v\":{\"a\":1},\"y\":222}");
Console.WriteLine("Now using the client formatter");
ChannelFactory<ITestService> newFactory = new ChannelFactory<ITestService>(webBinding, new EndpointAddress(baseAddress + "/json"));
newFactory.Endpoint.Behaviors.Add(new NewtonsoftJsonBehavior());
ITestService newProxy = newFactory.CreateChannel();
Console.WriteLine(newProxy.Add(444, 555));
Console.WriteLine(newProxy.EchoPet(new Pet { Color = "gold", Id = 2, Markings = "Collie", Name = "Lassie" }));
Console.WriteLine(newProxy.GetPerson());
Console.WriteLine("Press ENTER to close");
Console.ReadLine();
host.Close();
Console.WriteLine("Host closed");
}
示例12: Open
public static void Open(string tibcoEndpointUri) {
Uri uri;
if (!Uri.TryCreate(tibcoEndpointUri, UriKind.Absolute, out uri)) {
uri = new Uri("http://0.0.0.0:50701");
}
_host = new ServiceHost(typeof(OscarServices), uri);
var smb = new ServiceMetadataBehavior {
HttpGetEnabled = true,
};
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
_host.Description.Behaviors.Add(smb);
var sdb = _host.Description.Behaviors.Find<ServiceDebugBehavior>();
if (sdb == null) {
sdb = new ServiceDebugBehavior();
_host.Description.Behaviors.Add(sdb);
}
sdb.IncludeExceptionDetailInFaults = false;
sdb.HttpHelpPageEnabled = false;
_host.AddServiceEndpoint(ServiceMetadataBehavior.MexContractName, MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
var bhb = new BasicHttpBinding() { Namespace = "urn:Mpcr.Services.Oscar" };
bhb.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
bhb.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
_host.AddServiceEndpoint(typeof(IOscarServices), bhb, "");
_host.Authorization.ServiceAuthorizationManager = new TibcoAuthManager();
_host.Open();
}
示例13: ServiceHost
public override ServiceHostBase CreateServiceHost
(string service, Uri[] baseAddresses)
{
ServiceHost host = new ServiceHost(typeof(IssHosted.ServiceInterfaces.EchoService),
baseAddresses);
host.AddServiceEndpoint(typeof(IEchoService), new ServiceproviderBinding(true), "");
host.AddServiceEndpoint(typeof(IEchoService), new ServiceproviderBinding(false), "");
// Configure our certificate and issuer certificate validation settings on the service credentials
host.Credentials.ServiceCertificate.SetCertificate(SigningCertificateNameGenevaService, StoreLocation.LocalMachine, StoreName.My);
// Enable metadata generation via HTTP GET
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpsGetEnabled = true;
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);
host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpsBinding(), "mex");
host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
// Configure the service host to use the Geneva Framework
ServiceConfiguration configuration = new ServiceConfiguration();
configuration.IssuerNameRegistry = new TrustedIssuerNameRegistry();
configuration.SecurityTokenHandlers.Configuration.AudienceRestriction.AllowedAudienceUris.Add(new Uri("http://localhost/Echo/service.svc/Echo"));
configuration.SecurityTokenHandlers.Configuration.AudienceRestriction.AllowedAudienceUris.Add(new Uri("http://localhost:6020/Echo"));
configuration.SecurityTokenHandlers.Configuration.AudienceRestriction.AllowedAudienceUris.Add(new Uri("https://172.30.161.162:8181/poc-provider/ProviderService"));
configuration.SecurityTokenHandlers.Configuration.AudienceRestriction.AllowedAudienceUris.Add(new Uri("https://172.16.232.1:8181/poc-provider/ProviderService"));
configuration.SecurityTokenHandlers.Configuration.AudienceRestriction.AllowedAudienceUris.Add(new Uri("http://csky-pc/test/Service1.svc"));
FederatedServiceCredentials.ConfigureServiceHost(host, configuration);
return host;
}
示例14: ServicoProtocoloNETTCP
static void ServicoProtocoloNETTCP()
{
//Configuro a URL que vou SUBIR(DISPONIBILIZAR) O SERVIÇO WCF
Uri EnderecoServico = new Uri("net.tcp://localhost:8181/Demonstracao2/MeuServico");
//Classe serve para (HOSPEDAR, ARMAZENAR) O SERVIÇO WCF
//Informo o nome do SERVIÇO (Servicos.Contato)
//Informo o endereço que vou SUBIR O SERVIÇO
ServiceHost Host = new ServiceHost(typeof(Servicos.Contato), EnderecoServico);
//Habilitei o WSDL para os clientes
//WSDL = MEX no protocolo NET.TCP
Host.Description.Behaviors.Add(new ServiceMetadataBehavior());
//Configuração do WSDL(MEX)
Host.AddServiceEndpoint(typeof(IMetadataExchange),
MetadataExchangeBindings.CreateMexTcpBinding(),
"MEX/");
//Adicionei o ENDPOINT (Contrato que vai ser trafegado para o cliente)
//Adicionei o ENDPOINT (Tipo de Binding (PROTOCOLO))
//Adicionei o ENDPOINT (Nome do SERVIÇO)
Host.AddServiceEndpoint(typeof(Servicos.IContato),
new NetTcpBinding(),
"Servicos.Contato");
//Liguei o SERVIÇO
Host.Open();
}
示例15: OnStart
protected override void OnStart(string[] args)
{
var baseAddresses = new Uri[]
{
new Uri(Properties.Settings.Default.ServiceHttpUri),
new Uri(Properties.Settings.Default.ServiceNamedPipeUri),
};
_serviceHost = new ServiceHost(_singletonService, baseAddresses);
_serviceHost.AddServiceEndpoint(typeof(ILocationService),
new BasicHttpBinding(),
"Location");
_serviceHost.AddServiceEndpoint(typeof(ILocationService),
new NetNamedPipeBinding(),
"Location");
var smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
_serviceHost.Description.Behaviors.Add(smb);
_serviceHost.Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
_serviceHost.Open();
}