// Copyright (c) Microsoft Corporation. All Rights Reserved.
using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.Security;
[assembly:AllowPartiallyTrustedCallers()]
namespace Microsoft.ServiceModel.Samples.XmlRpc{
public class XmlRpcServiceHost : ServiceHost
{
public XmlRpcServiceHost():base()
{
}
public XmlRpcServiceHost(Type serviceType, params Uri[] baseAddresses):base(serviceType,baseAddresses)
{
}
public XmlRpcServiceHost(object singletonInstance, params Uri[] baseAddresses):base(singletonInstance,baseAddresses)
{
}
protected override void InitializeRuntime()
{
if (base.Description.Endpoints.Count == 0)
{
Type implementedContract = null;
foreach (ContractDescription contractDescription in base.ImplementedContracts.Values)
{
implementedContract = contractDescription.ContractType;
break;
}
foreach (Uri uri in base.BaseAddresses)
{
if (uri.Scheme == Uri.UriSchemeHttps)
{
base.AddServiceEndpoint(implementedContract, new XmlRpcHttpBinding(XmlRpcHttpSecurityMode.Transport), uri);
}
else if (uri.Scheme == Uri.UriSchemeHttp)
{
base.AddServiceEndpoint(implementedContract, new XmlRpcHttpBinding(XmlRpcHttpSecurityMode.None), uri);
}
}
}
foreach (ServiceEndpoint endpoint in this.Description.Endpoints)
{
if (endpoint.Binding is XmlRpcHttpBinding)
{
if (endpoint.Behaviors.Find<XmlRpcEndpointBehavior>() == null)
{
endpoint.Behaviors.Add( new XmlRpcEndpointBehavior() );
}
}
}
base.InitializeRuntime();
}
}
}
|