本文整理汇总了C#中System.ServiceModel.Description.WebHttpBehavior类的典型用法代码示例。如果您正苦于以下问题:C# WebHttpBehavior类的具体用法?C# WebHttpBehavior怎么用?C# WebHttpBehavior使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebHttpBehavior类属于System.ServiceModel.Description命名空间,在下文中一共展示了WebHttpBehavior类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Console.WriteLine("Инициализация...");
var properties = ConnectionSettings.Default;
var baseUrl = new Uri(properties.host);
var contractType = typeof (IRestBridgeContract);
var binding = new WebHttpBinding(WebHttpSecurityMode.None);
binding.ContentTypeMapper = new JsonContentTypeMapper();
var server = new ServiceHost(typeof (CastDriverBridgeEmulatorImpl));
var endPoint = server.AddServiceEndpoint(contractType, binding, baseUrl);
var behavior = new WebHttpBehavior();
behavior.FaultExceptionEnabled = false;
behavior.HelpEnabled = true;
behavior.DefaultOutgoingRequestFormat = WebMessageFormat.Json;
behavior.DefaultOutgoingResponseFormat = WebMessageFormat.Json;
endPoint.Behaviors.Add(behavior);
Console.WriteLine("Инициализация завершена.");
Console.WriteLine("Запуск сервера...");
server.Open();
Console.WriteLine("Сервер запущен. Адрес сервера: {0}\nДля остановки нажмите Enter.", properties.host);
Console.ReadLine();
Console.WriteLine("Остановка сервера...");
server.Close();
Console.WriteLine("Сервер остановлен.");
Console.ReadLine();
}
示例2: OnOpening
/// <summary>
/// Configures service endpoint and adds special behaviors to it (WebHttp and CorsSupport)
/// </summary>
protected override void OnOpening()
{
var securityMode = BaseAddresses.FirstOrDefault().Scheme == "https" ? WebHttpSecurityMode.Transport : WebHttpSecurityMode.None;
var receiveTimeout = new TimeSpan(1, 0, 0);
var defaultWebHttpBehavior = new WebHttpBehavior() {
AutomaticFormatSelectionEnabled = true,
DefaultBodyStyle = WebMessageBodyStyle.Wrapped,
DefaultOutgoingRequestFormat = WebMessageFormat.Json,
HelpEnabled = false
};
var endPoint = new ServiceEndpoint(
ContractDescription.GetContract(Description.ServiceType),
new WebHttpBinding(securityMode) {
UseDefaultWebProxy = false,
ReceiveTimeout = receiveTimeout,
MaxBufferSize = Config.MaxBufferSize,
MaxReceivedMessageSize = Config.MaxReceivedMessageSize
},
new EndpointAddress(BaseAddresses.FirstOrDefault())
);
endPoint.EndpointBehaviors.Add(defaultWebHttpBehavior);
endPoint.EndpointBehaviors.Add(new CorsSupportBehavior());
endPoint.EndpointBehaviors.Add(new BrowserCompatibilityBehavior());
AddServiceEndpoint(endPoint);
base.OnOpening();
}
示例3: Main
static void Main(string[] args)
{
Uri baseAddress = new Uri("http://localhost:8000/");
ServiceHost selfHost = new WebServiceHost(typeof(MonitorService), baseAddress);
try
{
// Step 3 Add a service endpoint.
var t = new WebHttpBinding();
selfHost.AddServiceEndpoint(typeof(IMonitorService), t, "test");
WebHttpBehavior whb = new WebHttpBehavior();
// Step 4 Enable metadata exchange.
ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
selfHost.Description.Behaviors.Add(smb);
// Step 5 Start 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();
}
}
示例4: QueryServiceHost
public QueryServiceHost(Uri address, object service)
{
host = new WebServiceHost(service);
host.AddServiceEndpoint(typeof(IQueryService), new WebHttpBinding(), address);
WebHttpBehavior behavior = new WebHttpBehavior();
host.Description.Endpoints[0].Behaviors.Add(behavior);
}
示例5: GetServiceHost
public static ServiceHost GetServiceHost(Uri baseAddress)
{
ServiceHost host = new ServiceHost(typeof(KORTService), baseAddress);
ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IService), GetBinding(), baseAddress);
WebHttpBehavior httpBehavior = new WebHttpBehavior {DefaultBodyStyle = WebMessageBodyStyle.Bare };
endpoint.Behaviors.Add(httpBehavior);
return host;
}
示例6: AddBiningParameters
public void AddBiningParameters ()
{
var se = CreateEndpoint ();
var b = new WebHttpBehavior ();
var pl = new BindingParameterCollection ();
b.AddBindingParameters (se, pl);
Assert.AreEqual (0, pl.Count, "#1");
}
示例7: DefaultValues
public void DefaultValues ()
{
var b = new WebHttpBehavior ();
Assert.AreEqual (WebMessageBodyStyle.Bare, b.DefaultBodyStyle, "#1");
Assert.AreEqual (WebMessageFormat.Xml, b.DefaultOutgoingRequestFormat, "#2");
Assert.AreEqual (WebMessageFormat.Xml, b.DefaultOutgoingResponseFormat, "#3");
Assert.IsFalse (b.AutomaticFormatSelectionEnabled, "#11");
Assert.IsFalse (b.FaultExceptionEnabled, "#12");
Assert.IsFalse (b.HelpEnabled, "#13");
}
示例8: HelpPage
public HelpPage(WebHttpBehavior behavior, ContractDescription description)
{
this.operationInfoDictionary = new Dictionary<string, OperationHelpInformation>();
this.operationPageCache = new NameValueCache<string>();
this.helpPageCache = new NameValueCache<string>();
foreach (OperationDescription od in description.Operations)
{
operationInfoDictionary.Add(od.Name, new OperationHelpInformation(behavior, od));
}
}
示例9: Main
static void Main(string[] args)
{
const String soapServiceEndpointAddress = "SOAP";
const String restServiceEndpointAddress = "REST";
Uri soapBaseAddress = new Uri("http://localhost:5000/OraclePermissionGeneratorWebServiceAPI");
Uri restBaseAddress = new Uri("http://localhost:5001/OraclePermissionGeneratorWebServiceAPI");
// Create and start the service host
using (FileTrackingDataLogger trackingDataLogger = new FileTrackingDataLogger(@"C:\Temp\"))
{
Dictionary<string, OraclePermissionGeneratorDataInterfaceLayer> userDataRespository = new Dictionary<string, OraclePermissionGeneratorDataInterfaceLayer>();
SoapWebServiceApi soapApiInstance = new SoapWebServiceApi(userDataRespository, trackingDataLogger);
RestWebServiceApi restApiInstance = new RestWebServiceApi(userDataRespository, trackingDataLogger);
soapApiInstance.AddUser("[email protected]");
soapApiInstance.LoadDataModelFromFile("[email protected]", @"..\..\..\Resources\Tutorial 2.xml", @"..\..\..\Resources\ORACLE_PERMISSION_GENERATOR_CONFIG.xsd");
using (ServiceHost soapServiceHost = new ServiceHost(soapApiInstance, soapBaseAddress))
using (ServiceHost restServiceHost = new ServiceHost(restApiInstance, restBaseAddress))
{
// Set SOAP service host settings
ServiceMetadataBehavior soapServiceMetadataBehavior = new ServiceMetadataBehavior();
soapServiceMetadataBehavior.HttpGetEnabled = true;
soapServiceMetadataBehavior.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
soapServiceHost.Description.Behaviors.Add(soapServiceMetadataBehavior);
BasicHttpBinding soapBinding = new BasicHttpBinding();
ServiceEndpoint soapEndpoint = soapServiceHost.AddServiceEndpoint(typeof(ISoapWebServiceApi), soapBinding, soapServiceEndpointAddress);
// Set single instance
soapServiceHost.Description.Behaviors.Find<ServiceBehaviorAttribute>().InstanceContextMode = InstanceContextMode.Single;
// Turn on option to include exception in any web service interface errors
soapServiceHost.Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
// Set REST service host settings
ServiceMetadataBehavior restServiceMetadataBehavior = new ServiceMetadataBehavior();
restServiceMetadataBehavior.HttpGetEnabled = true;
restServiceMetadataBehavior.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
restServiceHost.Description.Behaviors.Add(restServiceMetadataBehavior);
WebHttpBinding restBinding = new WebHttpBinding();
ServiceEndpoint restEndpoint = restServiceHost.AddServiceEndpoint(typeof(IRestWebServiceApi), restBinding, restServiceEndpointAddress);
WebHttpBehavior restBehavior = new WebHttpBehavior();
restEndpoint.Behaviors.Add(restBehavior);
restServiceHost.Description.Behaviors.Find<ServiceBehaviorAttribute>().InstanceContextMode = InstanceContextMode.Single;
restServiceHost.Description.Behaviors.Find<ServiceDebugBehavior>().IncludeExceptionDetailInFaults = true;
// Start the services
soapServiceHost.Open();
restServiceHost.Open();
Console.WriteLine("Press [Enter] to stop the service.");
Console.ReadLine();
restServiceHost.Close();
soapServiceHost.Close();
}
}
}
示例10: WebMessageFormatter
public WebMessageFormatter (OperationDescription operation, ServiceEndpoint endpoint, QueryStringConverter converter, WebHttpBehavior behavior)
{
this.operation = operation;
this.endpoint = endpoint;
this.converter = converter;
this.behavior = behavior;
ApplyWebAttribute ();
// This is a hack for WebScriptEnablingBehavior
var jqc = converter as JsonQueryStringConverter;
if (jqc != null)
BodyName = jqc.CustomWrapperName;
}
示例11: OpenRESTfulTestHost
public static void OpenRESTfulTestHost()
{
ServiceHost host = new ServiceHost(typeof(RESTfulTest), new Uri("http://localhost:8088/"));
ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IRESTfulTest), new WebHttpBinding(), "restful");
WebHttpBehavior httpBehavior = new WebHttpBehavior();
endpoint.Behaviors.Add(httpBehavior);
//ServiceMetadataBehavior behavior = new ServiceMetadataBehavior();
//behavior.HttpGetEnabled = true;
//host.Description.Behaviors.Add(behavior);
host.Open();
}
示例12: CreateServiceHost
protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
{
// Check security requirement.
bool integratedSecurity = (Service.GetAuthenticationSchemes(baseAddresses[0]) & AuthenticationSchemes.Anonymous) != AuthenticationSchemes.Anonymous;
// Initialize host and binding.
ServiceHost host = new ServiceHost(serviceType, baseAddresses);
// Enable metadata publishing.
ServiceMetadataBehavior serviceBehavior = host.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (serviceBehavior == null)
{
serviceBehavior = new ServiceMetadataBehavior();
host.Description.Behaviors.Add(serviceBehavior);
}
serviceBehavior.HttpGetEnabled = true;
// Add REST endpoint.
WebHttpBinding restBinding = new WebHttpBinding();
WebHttpBehavior restBehavior = new WebHttpBehavior();
ServiceEndpoint restEndpoint = host.AddServiceEndpoint(typeof(ISecurityService), restBinding, "rest");
if (integratedSecurity)
{
// Enable security on the binding.
restBinding.Security.Mode = WebHttpSecurityMode.TransportCredentialOnly;
restBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
}
#if !MONO
restBehavior.HelpEnabled = true;
#endif
restEndpoint.Behaviors.Add(restBehavior);
// Add SOAP endpoint.
BasicHttpBinding soapBinding = new BasicHttpBinding();
if (integratedSecurity)
{
// Enable security on the binding.
soapBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
soapBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
}
host.AddServiceEndpoint(typeof(ISecurityService), soapBinding, "soap");
host.AddServiceEndpoint(typeof(IMetadataExchange), soapBinding, "soap/mex");
return host;
}
示例13: StartHost
public static WebHost StartHost()
{
Trace.TraceInformation("Starting host..");
WebHttpBinding binding = new WebHttpBinding(WebHttpSecurityMode.None);
ServiceEndpoint endPoint = new ServiceEndpoint(ContractDescription.GetContract(typeof(BlocksOptimizationServices)),
binding, new EndpointAddress(WebHostAdress));
WebHttpBehavior webBehavior = new WebHttpBehavior();
endPoint.Behaviors.Add(webBehavior);
ServiceHost serviceHost = new ServiceHost(typeof(BlocksOptimizationServices));
serviceHost.AddServiceEndpoint(endPoint);
serviceHost.Open();
Trace.TraceInformation("Service Host Started.");
return new WebHost(serviceHost);
}
示例14: ApplyDispatchBehavior
public void ApplyDispatchBehavior ()
{
var se = CreateEndpoint ();
var od = se.Contract.Operations [0];
// in .NET 3.5 it adds "OperationSelectorBehavior"
int initCB = ContractDescription.GetContract (typeof (IMyService)).Behaviors.Count;
// in .NET 3.5 it adds
// - OperationInvokeBehavior,
// - OperationBehaviorAttribute,
// - DataContractSerializerOperationBehavior and
// - DataContractSerializerOperationGenerator
int initOB = od.Behaviors.Count;
// Assert.AreEqual (1, initCB, "#0-1");
// Assert.AreEqual (4, initOB, "#0-2");
var b = new WebHttpBehavior ();
se.Behaviors.Add (b);
var ed = new EndpointDispatcher (se.Address, se.Contract.Name, se.Contract.Namespace);
IChannelListener l = new WebHttpBinding ().BuildChannelListener<IReplyChannel> (new BindingParameterCollection ());
var cd = new ChannelDispatcher (l);
cd.Endpoints.Add (ed); // without it this test results in NRE (it blindly adds IErrorHandler).
Assert.AreEqual (0, cd.ErrorHandlers.Count, "#1-1");
Assert.IsNull (ed.DispatchRuntime.OperationSelector, "#1-2");
Assert.AreEqual (1, se.Behaviors.Count, "#1-3-1");
Assert.AreEqual (initCB, se.Contract.Behaviors.Count, "#1-3-2");
Assert.AreEqual (initOB, od.Behaviors.Count, "#1-3-3");
Assert.IsTrue (ed.AddressFilter is EndpointAddressMessageFilter, "#1-4");
b.ApplyDispatchBehavior (se, ed);
// FIXME: implement and enable it later
//Assert.AreEqual (1, cd.ErrorHandlers.Count, "#2-1");
Assert.AreEqual (typeof (WebHttpDispatchOperationSelector),
ed.DispatchRuntime.OperationSelector.GetType (), "#2-2");
Assert.AreEqual (1, se.Behaviors.Count, "#3-1");
Assert.AreEqual (initCB, se.Contract.Behaviors.Count, "#3-2");
Assert.AreEqual (initOB, od.Behaviors.Count, "#3-3");
// ... i.e. nothing is added.
Assert.IsTrue (ed.AddressFilter is PrefixEndpointAddressMessageFilter, "#3-4");
Assert.AreEqual (0, ed.DispatchRuntime.Operations.Count, "#4-0"); // hmm... really?
}
示例15: UProveThreadWorkerProver
public UProveThreadWorkerProver()
{
WebHttpBinding binding = new WebHttpBinding();
UProveRestServiceProver instance = UProveRestServiceProver.Instance;
_host = new WebServiceHost(instance, new Uri(ParseConfigManager.GetAddress(), ParseConfigManager.GetProverApiPath()));
_serviceEndPoint = _host.AddServiceEndpoint(typeof(IUProveRestServiceProver), binding, "");
WebHttpBehavior enableHelp = new WebHttpBehavior();
enableHelp.HelpEnabled = true;
enableHelp.DefaultOutgoingResponseFormat = WebMessageFormat.Json;
enableHelp.DefaultOutgoingRequestFormat = WebMessageFormat.Json;
_serviceEndPoint.EndpointBehaviors.Add(enableHelp);
if (ParseConfigManager.SetupTimeProfiles())
{
_serviceEndPoint.Behaviors.Add(new WcfTimeProfileEndPointLogger());
}
}