Question : Dynamically passing the parameter the service constructor (without configuration file)

Hi I am sucesfully accessing the WCF service using the static configuration and C# WCF code.

App.Config looks like

*********************************
<client>
      <endpoint address="net.tcp://SC-Server-APP01:50010/Common/Configuration" name="Configuration" binding="netTcpBinding" contract="Sysrepublic.Common.Services.Configuration.IConfigurationOperations">
        <identity>
          <userPrincipalName value=""></userPrincipalName>
        </identity>
      </endpoint>
</client>

//C# Code that works is


using (ServiceClientWrapper<IDefinition> wrapperForIDefinition = new ServiceClientWrapper<IDefinition>("somevalue"))
               
                {
                    questionsRepository = new QuestionsRepository(wrapperForIDefinition.Proxy.GetDefinitions("username"));
                }

*********************************

Above things works fine. but I want to access the WCF service without using the configuration (dynamic C# Code)

something like this i tried but didnt work. I really need to pass the constructor parameter dynamically in the below code or someother code.

*********************************
EndpointAddress address = new EndpointAddress((new Uri("net.tcp://SC-Server-APP01:50010/Common/Configuration")));

            NetTcpBinding binding = new NetTcpBinding();
           
            ChannelFactory<IDefinition> factory =new ChannelFactory<IDefinition>(binding, address);
           
            IDefinition IDefinition1 = factory.CreateChannel();

            IEnumerable<ExplorerDefinition> ex= IDefinition1.GetDefinitions("someuser");

*********************************
Error at  line -> IEnumerable<ExplorerDefinition> ex= IDefinition1.GetDefinitions("someuser");




Answer : Dynamically passing the parameter the service constructor (without configuration file)

I found the solutions. Thanks now. it is working fine now.

EndpointAddress address = new EndpointAddress(new Uri("net.tcp://SC-Server-APP01:50010/Common/Definition"), EndpointIdentity.CreateUpnIdentity("svcrange@dev"));

            NetTcpBinding netTcpBinding = new NetTcpBinding();
            netTcpBinding.MaxReceivedMessageSize = int.MaxValue;

            netTcpBinding.TransactionFlow = true;
            netTcpBinding.TransactionProtocol = TransactionProtocol.OleTransactions;
            netTcpBinding.ReaderQuotas.MaxDepth = int.MaxValue;
            netTcpBinding.ReaderQuotas.MaxStringContentLength = int.MaxValue;
            netTcpBinding.ReaderQuotas.MaxArrayLength = int.MaxValue;

            ChannelFactory<IDefinition> factory = new ChannelFactory<IDefinition>(netTcpBinding, address);

            factory.Endpoint.Behaviors.Add(new AttachExtendedHeadersBehavior()
            {
                Domain = "range",
                Culture = "",
                User = ""
            });

            IDefinition IDefinition1 = factory.CreateChannel();



            var defs = IDefinition1.GetAllDefinitions("someuser");



Random Solutions  
 
programming4us programming4us