tags:

views:

131

answers:

2

Every time my program runs vs adds the default configuration to my app.config file. At that run it works fine, but at the next run it actually tries to read the config.

The problem is that the default configuration has errors, it adds the attribute "Address", but attritbutes are not allowed to have capitals so it throws an exception.

This means I have to remove the bad section every run!

I've tried to configure the .config but it gives errors.

Here is the code that I use to host the server:

private static System.Threading.AutoResetEvent stopFlag = new System.Threading.AutoResetEvent(false);
ServiceHost host = new ServiceHost(typeof(Service), new Uri("http://localhost:8000"));
host.AddServiceEndpoint(typeof(IService), new BasicHttpBinding(), "ChessServer");
host.Open();
stopFlag.WaitOne();
host.Close();

Here is the client code that calls the server:

ChannelFactory<IChessServer> scf;
scf = new ChannelFactory<IService>
              (new BasicHttpBinding(), "http://localhost:8000");
IService service = scf.CreateChannel();

Thanks for any help.

Edit: Sorry it took me so long, I've been trying to use DualWSHttpBinding instead (since I actually need the server to call client methods to anyway) but still generates the config file. Here's the entire auto-generated config file:

<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><system.serviceModel>
        <behaviors>
            <serviceBehaviors>
                <behavior name="">
                    <serviceMetadata httpGetEnabled="true" />
                    <serviceDebug includeExceptionDetailInFaults="false" />
                </behavior>
            </serviceBehaviors>
        </behaviors>
        <services>
            <service name="Chess.ChessService">
                <endpoint Address="" binding="wsHttpBinding" contract="Chess.IChessServer">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint Address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <Add baseAddress="http://localhost:8732/Design_Time_Addresses/Chess/ChessService/" />
                    </baseAddresses>
                </host>
            </service>
            <service name="Chess.ChessClient">
                <endpoint Address="" binding="wsHttpBinding" contract="Chess.IChessClient">
                    <identity>
                        <dns value="localhost" />
                    </identity>
                </endpoint>
                <endpoint Address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
                <host>
                    <baseAddresses>
                        <Add baseAddress="http://localhost:8732/Design_Time_Addresses/Chess/ChessClient/" />
                    </baseAddresses>
                </host>
            </service>
        </services>
    </system.serviceModel>
</configuration>
+1  A: 

You're quite mistaken. Attribute and element names may be upper or lower case.

What makes you think that the case of the attribute is the problem? And what makes you think that the app.config is changed on every run?

John Saunders
Because of this error:"Unrecognized attribute 'Address'. Note that attribute names are case-sensitive."(C:\school\programming\C#\Server\bin\Debug\Server.vshost.exe.Config line 14)And because I get a message after every run that the config file changed and if I want to reload it.It probably changes the config because I leave the config empty.But I don't want to use any config. I want to host a server based on user input rather than static configuration.
MrFox
If the attribute is unrecognized, then it's for some reason other than the case. Why not post the XML that is being generated by WCF?
John Saunders
+1  A: 

Visual Studio does not re-create the WCF configuration on every run. It will re-create the WCF configuration every time you do an Update Service Reference on your service reference in the project - but it definitely doesn't automatically do that before every run - there must be something else causing you grief here.

Furthermore, you're not connecting to the correct address - your server defines it here:

ServiceHost host = new ServiceHost(..., new Uri("http://localhost:8000"));
host.AddServiceEndpoint(..., .., "ChessServer");

and this results in your endpoint address on the server being

http://localhost:8000/ChessServer

However, you're client appears to attempt to connect to

http://localhost:8000/

and there's no service there.

A last point: if you set up all your things like endpoints, bindings etc. in code, any changes to the config shouldn't even bother you at all - there must be something else causing your problems.

marc_s