problem with WCF and APP.config

Hello,
I have a problem with WCF:

I used the classic example from the VS 2005 Template:

the solution with 2 projects

1. WCFServiceLibrary project for the service, which contains

[ServiceContract()]
public interface IService1
...

and
public class service1 : IService1
{
...

2. my Host (console application)


If I do not use an App.config file everything works fine:
[CODE]
static void Main(string[] args)
{
Uri adresse = new Uri("http://localhost:6666/demo");

ServiceHost sh = new ServiceHost(typeof(WCFServiceLibrary.service1), adresse);

sh.AddServiceEndpoint(typeof(WCFServiceLibrary.IService1),
new BasicHttpBinding(),
adresse);

sh.Open();
Console.WriteLine("press Return...");
Console.ReadLine();
sh.Close();
}

[/CODE]

But now I want to put the ABC into an app.config. So I change my Code and build an app.config:

[CODE]
ServiceHost sh = new ServiceHost(typeof(WCFServiceLibrary.service1))
sh.Open();
Console.WriteLine("press Return...");
Console.ReadLine();
sh.Close();
[/CODE]


[APP.CONFIG]
<system.serviceModel>
<services>
<service name="WCFServiceLibrary.service1">
<endpoint address="http://localhost:6666/demo"
contract="WCFServiceLibrary.IService1"
binding="basicHttpBinding"/>

</service>
</services>
</system.serviceModel>
[/APP.CONFIG]

But now I get an exception at
ServiceHost sh = new ServiceHost(typeof(WCFServiceLibrary.service1))

System.TypeInitializationException wurde nicht behandelt.
Message="Der Typeninitialisierer fur System.ServiceModel.DiagnosticUtility hat eine Ausnahme verursacht."
Source="System.ServiceModel"
TypeName="System.ServiceModel.DiagnosticUtility"
StackTrace:
bei System.ServiceModel.Channels.CommunicationObject.set_TraceOpenAndClose(Boolean value)
bei System.ServiceModel.ServiceHostBase..ctor()
bei System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses)
bei Host.Program.Main(String[] args) in C:\sources\WCFServiceLibrary\Host\Program.cs:Zeile 15.
bei System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
bei System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
bei Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
bei System.Threading.ThreadHelper.ThreadStart_Context(Object state)
bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
bei System.Threading.ThreadHelper.ThreadStart()


what is wrong

Thank you very much,
Alex



Answer this question

problem with WCF and APP.config

  • jxl98c

    No,
    I have just switched the ports 5555 and 6666 for testing and forgot to correct them at my posting.

    Alex


  • mobile_hacker

    Could the issue be that in your App.config file you're point to the port 6666 yet in your Program.cs file you're creating a Uri for the Service Address that is using port 5555

    http://localhost:6666 != http://localhost:5555

    Hope this helps,
    Richie



  • TheMaj0r

    The TypeInitializationException from DiagnosticUtility is indicative of a setup issue.

    The final version is just out:

    http://www.netfx3.com/blogs/news_and_announcements/archive/2006/11/06/.NET-Framework-3.0-has-been-released_2100_.aspx

    Please try running the uninstall instructions/tool to uninstall previous versions, and then install the final bits, and let us know how it goes.



  • is98

    Hello again,
    thank you for your ideas but none worked.

    I have tried ServiceModelReg -r but the problem is still the same.

    I have uninstalled .NET Framework 3.0 and reinstalled it from
    http://www.microsoft.com/downloads/details.aspx FamilyID=19e21845-f5e3-4387-95ff-66788825c1af&DisplayLang=de

    I have also installed the Framework 3.0 onto an other PC which encounters the same problem.

    No errors in eventlog. WCFTracing in my app.config I am not sure, see codefile below.

    Here's the code:
    One project with 2 Elements. The Servicelibrarydll and the console-host.
    #############################1. my ServiceLibrary (compiled as a DLL)
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.ServiceModel;
    using System.Runtime.Serialization;


    namespace WCFServiceLibrary
    {

    [ServiceContract()]
    public interface IService1
    {
    [OperationContract]
    string MyOperation1(string myValue);
    [OperationContract]
    string MyOperation2(DataContract1 dataContractValue);
    }

    public class service1 : IService1
    {
    public string MyOperation1(string myValue)
    {
    return "Hello: " + myValue;
    }
    public string MyOperation2(DataContract1 dataContractValue)
    {
    return "Hello: " + dataContractValue.FirstName;
    }
    }

    [DataContract]
    public class DataContract1
    {
    string firstName;
    string lastName;

    [DataMember]
    public string FirstName
    {
    get { return firstName; }
    set { firstName = value; }
    }
    [DataMember]
    public string LastName
    {
    get { return lastName; }
    set { lastName = value; }
    }
    }

    }
    #############################

    #############################2. my HOST as a Console Application
    (set a reference to my DLL)
    #############################2.1 my App.config
    <system.serviceModel>
    <services>
    <service name = "WCFServiceLibrary.service1" behaviorConfiguration="behaviorConfig">
    <host>
    <baseAddresses>
    <add baseAddress="http://localhost:6666/demo" />
    </baseAddresses>
    </host>
    <endpoint
    address = ""
    binding = "basicHttpBinding"
    bindingConfiguration = "bindingConfig"
    contract = "WCFServiceLibrary.IService1" />
    </service>
    </services>

    <behaviors>
    <serviceBehaviors>
    <behavior name = "behaviorConfig">
    </behavior>

    </serviceBehaviors>
    </behaviors>
    <bindings>
    <basicHttpBinding>
    <binding name = "bindingConfig">
    </binding>
    </basicHttpBinding>
    </bindings>
    </system.serviceModel>


    I have tried both
    <endpoint
    address = ""

    and

    <endpoint
    address = "http://localhost:6666/demo"

    #############################

    #############################2.2 my Program.cs

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.ServiceModel;
    using WCFServiceLibrary;

    namespace Host
    {
    class Program
    {
    static void Main(string[] args)
    {
    ServiceHost sh = new ServiceHost(typeof(WCFServiceLibrary.service1));

    sh.Open();
    Console.WriteLine("press Return...");
    Console.ReadLine();
    sh.Close();

    }
    }
    }


    #############################

    and this do not work.

    If I rename app.config to app.nuts and change my program to
    #############################
    static void Main(string[] args)
    {
    Uri adresse = new Uri("http://localhost:5555/demo");

    ServiceHost sh = new ServiceHost(typeof(WCFServiceLibrary.service1), adresse);

    sh.AddServiceEndpoint(typeof(WCFServiceLibrary.IService1),
    new BasicHttpBinding(),
    adresse);

    sh.Open();
    Console.WriteLine("press Return...");
    Console.ReadLine();
    sh.Close();

    #############################
    everthing is fine.

    Any (more) ideas I do not want to set the adress/binding in my codefile by hardcoding.

    Thanx, Alex



  • aguess

    The problem will be caused by a bad installation of WCF, to resolve this issue, you can reinstall the IIS ScriptMaps and Configuration handlers. To make it go to WCF installation directory and execute the ServiceModelReg.exe tool using the -r option:

    cd %windir%\microsoft.net\framework\v3.0\wcf
    ServiceModelReg -r

    Regards,



  • Mike Thurber

    Try it :

    <system.serviceModel>
    <services
    >
    <
    service name = "WCFServiceLibrary.service1" behaviorConfiguration="behaviorConfig"
    >
    <
    host
    >
    <
    baseAddresses
    >
    <
    add baseAddress="http://localhost:6666/demo"
    />
    </
    baseAddresses
    >
    </
    host>
    <
    endpoint
    address = ""
    binding = "basicHttpBinding"
    bindingConfiguration = "bindingConfig"
    contract = "WCFServiceLibrary.IService1"
    />
    </
    service>
    </
    services>
    <
    behaviors>
    <
    serviceBehaviors>
    <
    behavior name = "behaviorConfig">
    </behavior>
    |
    </
    serviceBehaviors>
    </
    behaviors>
    <
    bindings>
    <
    basicHttpBinding>
    <
    binding name = "bindingConfig">
    </binding>
    </
    basicHttpBinding>
    </
    bindings>
    </
    system.serviceModel>


  • Joe Au

    FYI, I have moved this thread to ".NET Framework Setup", since the problem is indicative of a setup issue.

  • Severin123

    Are you running the latest WCF bits

    Is there any error messages in your event log

    Do you have WCF tracing configured in your app.config

    Dave



  • Ke Sun

    Can you post your code here
  • Joao Richiard

    Hello,
    sorry, but it did not work. Still the same problem.

    Any more ideas

    Thanx, Alex


  • problem with WCF and APP.config