none
Configuration help. RRS feed

  • Question

  • I am having some configuration problems and I would like to solicite some help from this group. I have tried reading "Programming 'INDIGO'" on configuration but it seems that many of the tag names and configuration sections have changed so that it is very hard to take samples from the book and apply them. Is there a better reference on configuration of server and client? Where would be the best place to go for samples? At a very basic level I would like to configure a client and server to use or listen on an HTTP address and a TCP address. This seems simple enough but the configuration has me tripped up right now.

    Thank you.

    Kevin

    Thursday, February 15, 2007 3:34 PM

Answers

  • If you have a working ‘programmatic’ CustomBinding, you can always generate the corresponding config binding.  Below is a short sample that shows how to generate config from code. 

     

    (Note that the technique of opening a service with an endpoint with binding X, and then pointing svcutil at the service to generate config, will not always generate the same binding X, since some binding settings (e.g. SendTimeout) are local and thus do not appear in policy/metadata.  The technique below works even for local settings.)

     

    using System;

    using System.ServiceModel;

    using System.ServiceModel.Description;

    using System.ServiceModel.Channels;

    using System.ServiceModel.Configuration;

    using System.Configuration;

     

    public class DemoHowToConvertBindingInCodeToAConfigFile

    {

        public static void Main()

        {

            BasicHttpBinding binding = new BasicHttpBinding();

            binding.SendTimeout = TimeSpan.FromSeconds(22);

            binding.Security.Mode = BasicHttpSecurityMode.Message;

            binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;

            CustomBinding custom = new CustomBinding(binding);

     

            Configuration machineConfig = ConfigurationManager.OpenMachineConfiguration();

            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();

            fileMap.ExeConfigFilename = "out.config";

            fileMap.MachineConfigFilename = machineConfig.FilePath;

            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

            config.NamespaceDeclared = true;

            ServiceContractGenerator scg = new ServiceContractGenerator(config);

            string sectionName, configName;

            scg.GenerateBinding(custom, out sectionName, out configName);

            config.Save();

        }

    }

     

    Thursday, February 15, 2007 8:34 PM
  • The best way to create configuration files for client and server is to use the SvcConfigEditor.exe tool that comes installed with the SDK.
    Thursday, February 15, 2007 3:38 PM
  • "Programming Indigo" is pretty out of date.  For samples, I would check out http://msdn2.microsoft.com/en-us/library/ms751514.aspx.  There should be lots of up-to-date configuration files with those.

     

    -James

     

    Thursday, February 15, 2007 7:48 PM
    Moderator

All replies

  • The best way to create configuration files for client and server is to use the SvcConfigEditor.exe tool that comes installed with the SDK.
    Thursday, February 15, 2007 3:38 PM
  • That may be the best way to do it but this editor does not help when I am not sure what sections to add. For example I can add a binding section with or without a name. I can do the same for service, profile, and behavior sections. I have not seen in this tool how to tie them all together. Simple things like allowing a client to receive more than 65536 bytes I can do programmatically but I have been unable to do via a configuration file. The tool makes sure that I have not mispelled the name of a section but information on what to put in the section to have it do what I want seems to be missing.

    Kevin

    Thursday, February 15, 2007 3:54 PM
  • "Programming Indigo" is pretty out of date.  For samples, I would check out http://msdn2.microsoft.com/en-us/library/ms751514.aspx.  There should be lots of up-to-date configuration files with those.

     

    -James

     

    Thursday, February 15, 2007 7:48 PM
    Moderator
  • If you have a working ‘programmatic’ CustomBinding, you can always generate the corresponding config binding.  Below is a short sample that shows how to generate config from code. 

     

    (Note that the technique of opening a service with an endpoint with binding X, and then pointing svcutil at the service to generate config, will not always generate the same binding X, since some binding settings (e.g. SendTimeout) are local and thus do not appear in policy/metadata.  The technique below works even for local settings.)

     

    using System;

    using System.ServiceModel;

    using System.ServiceModel.Description;

    using System.ServiceModel.Channels;

    using System.ServiceModel.Configuration;

    using System.Configuration;

     

    public class DemoHowToConvertBindingInCodeToAConfigFile

    {

        public static void Main()

        {

            BasicHttpBinding binding = new BasicHttpBinding();

            binding.SendTimeout = TimeSpan.FromSeconds(22);

            binding.Security.Mode = BasicHttpSecurityMode.Message;

            binding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.Certificate;

            CustomBinding custom = new CustomBinding(binding);

     

            Configuration machineConfig = ConfigurationManager.OpenMachineConfiguration();

            ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap();

            fileMap.ExeConfigFilename = "out.config";

            fileMap.MachineConfigFilename = machineConfig.FilePath;

            Configuration config = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

            config.NamespaceDeclared = true;

            ServiceContractGenerator scg = new ServiceContractGenerator(config);

            string sectionName, configName;

            scg.GenerateBinding(custom, out sectionName, out configName);

            config.Save();

        }

    }

     

    Thursday, February 15, 2007 8:34 PM
  • This was very helpful. I am down to what I think is my last configuration question. As far as I could see the samples do not give an endpoint a name. When I try to give an endpoint a name and refer to it in the following code:

    ChannelFactory<IServices> factory = new ChannelFactory<IServices>("MyEndpointName", address);

    I get an error:

    TestCase 'Buyseasons.BsiServices.Test.BsiServices.MessageTest.TestGetCatalogs'

    failed: System.InvalidOperationException: Could not find endpoint element with name 'MyEndpointName' and contract Test.Services.IServices' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this name could be found in the client element.

    at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(ServiceEndpoint serviceEndpoint, String configurationName)

    The configuration file has the 'name' as follows:

    <system.serviceModel>

    <client>

    <endpoint address="http://localhost:8003/Services" binding="wsHttpBinding"

    bindingConfiguration="httpBinding" contract="ServiceContracts.IServices"

    name="MyEndpointName" />

    Now what am I doing wrong?

    Thanks again.

    Kevin

    Thursday, February 15, 2007 10:54 PM
  • Thank you this was helpful. But the config file that is generated does not have any endpoints let alone names for the endpoint. I still am not sure what is meant when the channel factory is asking for the enpoint name in the constructor. What name should I supply there? I can't seem to link the configuration names with what is required for the channel factory.

    Thank you.

    Thursday, February 15, 2007 11:27 PM