0
У меня есть приложение консоли службы WCF. Все настройки сервиса жестко запрограммированы. Я хотел бы посмотреть, как эта конфигурация будет выглядеть в файле web.config
. На самом деле мне нужен раздел system.serviceModel
. Как сохранить настройки моего сервиса в файл?Сохранение конфигурации службы WCF в файл
namespace WCF_con
{
[ServiceContract]
interface IStringService
{
[OperationContract]
string Reverse(string s);
}
class MyStringService : IStringService
{
public string Reverse(string s)
{
return new string(s.Reverse().ToArray());
}
}
internal class Program
{
private static void Main(string[] args)
{
WSHttpBinding binding = new WSHttpBinding();
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard;
binding.Security.Mode = SecurityMode.None;
Uri baseAddress = new Uri("http://localhost:8000/StringService");
using (ServiceHost serviceHost =
new ServiceHost(typeof (MyStringService), baseAddress))
{
// Check to see if it already has a ServiceMetadataBehavior
ServiceMetadataBehavior smb =
serviceHost.Description.Behaviors.Find<ServiceMetadataBehavior>();
if (smb == null)
smb = new ServiceMetadataBehavior();
smb.HttpGetEnabled = true;
smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy12;
serviceHost.Description.Behaviors.Add(smb);
// Add MEX endpoint
serviceHost.AddServiceEndpoint(
ServiceMetadataBehavior.MexContractName,
MetadataExchangeBindings.CreateMexHttpBinding(),
"mex"
);
serviceHost.AddServiceEndpoint(typeof (IStringService), binding, baseAddress);
serviceHost.Open();
Console.WriteLine("The service is running. Press any key to stop.");
Console.ReadKey();
}
}
}
}