Good afternoon, I didn’t begin to study wcf (very little documentation), tried to implement my service and, as a result, I received an exception, which I’ve been fighting for a very long time, it’s impossible to solve the problem myself, if anyone can tell me please. Service itself

namespace TestService { [ServiceContract(Namespace = "http://TestService")] public interface IWCFService { [OperationContract] string SayHello(string name); [OperationContract] int Addition(int a, int b); [OperationContract] string TestString(string mas); //[OperationContractAttribute(AsyncPattern = true)] // IAsyncResult BeginServiceAsyncMethod(string msg, AsyncCallback callback, object asyncState); //string EndServiceAsyncMethod(IAsyncResult result); } //[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple, InstanceContextMode = InstanceContextMode.PerCall, ReleaseServiceInstanceOnTransactionComplete = true)] public class WCFService : IWCFService { public string SayHello(string name) { name = "zzzzzzzzzz" + name; return name; } public int Addition(int a, int b) { b = b + a; return b; } public string TestString(string mas) { //string per = "22222"; mas.Substring(1,3); mas.Remove(4); return mas; } } class Program : ServiceBase, IErrorHandler { public ServiceHost serviceHost = null; public System.Threading.Thread myThread; public static string CurDir=null; //System.Threading.Timer _Timer; public void ProvideFault(Exception error, MessageVersion version, ref Message fault) { } // HandleError. Log an error, then allow the error to be handled as usual. // Return true if the error is considered as already handled public bool HandleError(Exception error) { using (TextWriter tw = File.AppendText(@"c:\logs\error.txt")) { if (error != null) { tw.WriteLine("Exception: " + error.GetType().Name + " - " + error.Message); } tw.Close(); } return true; } public Program() { // Name the Windows Service ServiceName = "WCFTestService"; } static void Main(string[] args) { //Uri baseAddress = new Uri("http://localhost:8080/WCFService"); // Create the ServiceHost. // try // { ServiceBase.Run(new Program()); //Thread.Sleep(2000); Console.WriteLine("The service is ready at {0}"); Console.WriteLine("Press <Enter> to stop the service."); Console.ReadLine(); } protected override void OnStart(string[] args) { // Create a ServiceHost for the CalculatorService type and // provide the base address. try { serviceHost = new ServiceHost(typeof(WCFService), new Uri("http://localhost:8741/TestService")); // Open the ServiceHostBase to create listeners and start // listening for messages. serviceHost.Open(); CurDir = System.IO.Directory.GetCurrentDirectory(); int size = CurDir.Length; string necessary = CurDir.Substring(0, size - 21); System.IO.File.Create(necessary + "file1.txt"); myThread = new System.Threading.Thread(new System.Threading.ThreadStart(ThreadProc)); myThread.Start(); } catch (Exception error) { Console.WriteLine("Exception: " + error.GetType().Name + " - " + error.Message); HandleError(error); } } void ThreadProc() { //Create in thread new form and timer var _Timer = new System.Timers.Timer(); //_Timer.Tick += new EventHandler(timer_Tick); _Timer.Interval = 2000; _Timer.Start(); serviceHost.Close(); } protected override void OnStop() { if (serviceHost != null) { serviceHost.Close(); serviceHost = null; } } } 

app.config

 <?xml version="1.0" encoding="utf-8" ?> <configuration> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /> </startup> <system.diagnostics> <sources> <source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true" > <listeners> <add name="xml"/> </listeners> </source> <source name="System.ServiceModel.MessageLogging"> <listeners> <add name="xml"/> </listeners> </source> <source name="myUserTraceSource" switchValue="Information, ActivityTracing"> <listeners> <add name="xml"/> </listeners> </source> </sources> <sharedListeners> <add name="xml" type="System.Diagnostics.XmlWriterTraceListener" initializeData="c:\logs\Error.svclog" /> </sharedListeners> </system.diagnostics> <system.ServiceModel> <behaviors> <serviceBehaviors> <behavior name="debug"> <serviceMetadata httpGetEnabled="true" /> <serviceDebug includeExceptionDetailInFaults="true" /> </behavior> </serviceBehaviors> </behaviors> <services> <service name="TestService.WCFService" behaviorConfiguration="debug"> <endpoint address="" binding="basicHttpBinding" behaviorConfiguration="debug" contract="TestService.IWCFService" bindingConfiguration="FileUploadServiceBinding"/> <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" bindingConfiguration="FileUploadServiceBinding"/> <host> <baseAddresses> <add baseAddress="http://localhost:8741/TestService"/> </baseAddresses> </host> </service> </services> <bindings> <basicHttpBinding> <!-- buffer: 64KB; max size: 64MB --> <binding name="FileUploadServiceBinding" transferMode="Streamed" messageEncoding="Mtom" maxReceivedMessageSize="67108864" maxBufferSize="65536" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"> <security mode="Transport"> <transport clientCredentialType="None" /> </security> </binding> </basicHttpBinding> </bindings> </system.ServiceModel> </configuration> 

As a result, an error occurs.

Exception: TypeInitializationException - The type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an exception.

Help solve the problem, please.

Closed due to the fact that the essence of the question is incomprehensible to the participants awesoon , aleksandr barakin , Vladimir Glinskikh , Saidolim , Shilgen 2 Aug '15 at 18:07 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • And what about the InnerException ? - VladD
  • ConfigurationErrorsException: Configuration system failed to initialize - SergD29 9:01 pm
  • @ SergD29: And the rest of the relevant fields? What of you have information ticks pull? What is in ConfigurationErrorsException.Errors ? - VladD
  • I can't call ConfigurationErrorsException.Errors myself. Maybe somewhere there is an example - SergD29
  • Wrap up in Try Catch, in catch, put a breakpoint and look at the fields, it's just that .... - Mikhail Tatarintsev

0