yas4891
yas4891

Reputation: 4862

WCF: transform programmatic configuration into app.config

I have the following working programmatic configuration (server-side)

using (ServiceHost host = new ServiceHost(
                typeof(RequestHandler),
                new Uri[] { new Uri("net.pipe://localhost") }))
        {
            NetNamedPipeBinding tBinding = new NetNamedPipeBinding();


            host.AddServiceEndpoint(typeof(RequestInterface),
                tBinding, "Request");

            host.Open();
            Application.Run(new Form1());

        }

trying to turn this into code for app.config:

    <system.serviceModel>
<bindings>
  <netNamedPipeBinding>
    <binding
             closeTimeout="00:01:00"
             openTimeout="00:01:00"
             receiveTimeout="00:10:00"
             sendTimeout="00:01:00"
             transactionFlow="false"
             transferMode="Buffered"
             transactionProtocol="OleTransactions"
             hostNameComparisonMode="StrongWildcard"
             maxBufferPoolSize="524288"
             maxBufferSize="65536"
             maxConnections="10"
             maxReceivedMessageSize="65536">
      <security mode="Transport">
        <transport protectionLevel="EncryptAndSign" />
      </security>
    </binding>

  </netNamedPipeBinding>
</bindings>

<services>
  <service name="ServerApp.RequestHandler">
    <host>
      <add baseAddress="net.pipe://localhost/" />
    </host>
      <endpoint address="net.pipe://localhost/Request/"
              binding="netNamedPipeBinding"
              contract="AppLib.RequestInterface" />
  </service>
</services>

However, this doesn't seem to work - i.e. clients can not connect to this.

Do I have something wrong in my app.config code? Or do I have to something programmatically to tell .NET to use the configuration from app.config?

Upvotes: 0

Views: 1680

Answers (2)

Deepesh
Deepesh

Reputation: 5604

I think adding a mex endpoint of metadatexchange may resolve this, not sure but try it once. or its better you on the trace for service where you can find out exact problem.

Upvotes: 0

Joel Martinez
Joel Martinez

Reputation: 47749

No, aside from properly assigning the type/name in the config based on the service type ... which it looks like you've done correctly, you shouldn't have to do anything else to point to the configuration.

I didn't parse through the config, but honestly, you should probably use the Configuration Editor Tool to set up your service. It's probably the smallest little error, or mistype, or missed setting that's causing your service not to work. I've often said that XML may be human readable, but it's rarely human editable ... and IMO WCF configuration falls into that camp :-)

Upvotes: 2

Related Questions