Exemplo n.º 1
0
        private string GetXmlConfigFilePath()
        {
            string xml = $@"
<configuration> 
    <system.serviceModel>
        <bindings>
            <netTcpBinding>
                <binding name=""testBinding""/>
            </netTcpBinding>
        </bindings>
        <services>
            <service name=""{typeof(SomeService).FullName}"">
                <endpoint address=""net.tcp://localhost:6687/netTcp.svc/Buffered""
                          name=""SomeEndpoint""
                          binding=""netTcpBinding""
                          bindingConfiguration=""testBinding""
                          contract=""{typeof(ISomeService).FullName}"" />
            </service>
        </services>
    </system.serviceModel>
</configuration>";

            var fs = TemporaryFileStream.Create(xml);

            return(fs.Name);
        }
Exemplo n.º 2
0
        public void GetXmlConfigEndpoint_WithEmptyEndpointTest()
        {
            string xml = $@"
<configuration> 
    <system.serviceModel>
        <services>
            <service name=""{typeof(SomeService).FullName}"">
                  <endpoint address=""expectedAddress""
                          name=""expectedEndpointName""
                          binding=""netTcpBinding""                       
                          contract=""{typeof(ISomeService).FullName}"" />
            </service>
        </services>
   </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                using (ServiceProvider provider = CreateProvider(fs.Name))
                {
                    IConfigurationHolder settingHolder = GetConfigurationHolder(provider);

                    Assert.Throws <EndpointNotFoundException>(() => GetXmlConfigEndpointByEndpointName(settingHolder, string.Empty));
                }
            }
        }
Exemplo n.º 3
0
        public void ResolveBinding_WithUnknownBindingTest()
        {
            string xml = $@"
<configuration> 
    <system.serviceModel>
        <services>
            <service name=""{typeof(SomeService).FullName}"">
                  <endpoint address=""expectedAddress""
                          name=""expectedEndpointName""
                          binding=""netTcpBinding""                       
                          contract=""{typeof(ISomeService).FullName}"" />
            </service>
        </services>
   </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                using (ServiceProvider provider = CreateProvider(fs.Name))
                {
                    IConfigurationHolder settingHolder = GetConfigurationHolder(provider);

                    Assert.Throws <BindingNotFoundException>(() => settingHolder.ResolveBinding(nameof(NetTcpBinding), "unknown"));
                }
            }
        }
Exemplo n.º 4
0
        public void CreateDefaultBindingTest()
        {
            string expectedAddress      = "net.tcp://*****:*****@"
<configuration> 
    <system.serviceModel>
        <services>
            <service name=""{expectedServiceName}"">
                  <endpoint address=""{expectedAddress}""
                          name=""{expectedEndpointName}""
                          binding=""netTcpBinding""                       
                          contract=""{typeof(ISomeService).FullName}"" />
            </service>
        </services>
   </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                using (ServiceProvider provider = CreateProvider(fs.Name))
                {
                    IConfigurationHolder settingHolder = GetConfigurationHolder(provider);
                    IXmlConfigEndpoint   endpoint      = GetXmlConfigEndpointByEndpointName(settingHolder, expectedEndpointName);
                    Assert.Equal(expectedServiceName, endpoint.Service.FullName);
                    Assert.IsType <NetTcpBinding>(endpoint.Binding);
                    Assert.Equal("NetTcpBinding", endpoint.Binding.Name);
                }
            }
        }
Exemplo n.º 5
0
        private static ServiceModelSectionGroup GetSectionFromXml(TemporaryFileStream fs)
        {
            var cfg = new ConfigurationFileMap(fs.Name);

            System.Configuration.Configuration configuration = System.Configuration.ConfigurationManager.OpenMappedMachineConfiguration(cfg);
            var section = ServiceModelSectionGroup.GetSectionGroup(configuration);

            return(section);
        }
Exemplo n.º 6
0
        public void MultipleServiceTestWithSecurityMode()
        {
            string expectedServiceName              = typeof(SomeService).FullName;
            string expectedContractName             = typeof(ISomeService).FullName;
            string expectedNetTCPAddress            = "net.tcp://*****:*****@"
<configuration> 
    <system.serviceModel>
        <bindings>         
            <netTcpBinding>
                <binding name=""testBinding"">
                 <security mode=""None"" />
                 </binding>
            </netTcpBinding>
         <basicHttpBinding>
        <binding name=""Basic"">
          <security mode=""TransportWithMessageCredential"">
             <message clientCredentialType=""Certificate""/>
            </security >
          </binding >
        </basicHttpBinding >
          </bindings> 
        <services>            
            <service name=""{expectedServiceName}"">
                <endpoint address=""{expectedNetTCPAddress}""
                          binding=""netTcpBinding""
                          bindingConfiguration=""testBinding""
                          contract=""{expectedContractName}"" />
                <endpoint address=""{expectedBasicHttpAddress}""
                          name=""{expectedEndpointNameForBasicHttp}""
                          binding=""netTcpBinding""
                          bindingConfiguration=""testBinding""
                          contract=""{expectedContractName}"" />
            </service>
        </services>                             
    </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                using (ServiceProvider provider = CreateProvider(fs.Name))
                {
                    IConfigurationHolder settingHolder = GetConfigurationHolder(provider);
                    IXmlConfigEndpoint   endpoint      = GetXmlConfigEndpointByEndpointName(settingHolder, expectedEndpointNameForBasicHttp);
                    Assert.Equal(expectedServiceName, endpoint.Service.FullName);
                    Assert.Equal(expectedContractName, endpoint.Contract.FullName);
                    Assert.Equal(expectedBasicHttpAddress, endpoint.Address.AbsoluteUri);

                    endpoint = GetXmlConfigEndpointByEndpointName(settingHolder, string.Empty);
                    Assert.Equal(expectedServiceName, endpoint.Service.FullName);
                    Assert.Equal(expectedContractName, endpoint.Contract.FullName);
                    Assert.Equal(expectedNetTCPAddress, endpoint.Address.AbsoluteUri);
                }
            }
        }
Exemplo n.º 7
0
        public void BasicHttpBinding_WithCustomSetting()
        {
            string   expectedName = "basicHttpBindingConfig";
            long     expectedMaxReceivedMessageSize = 1073741824;
            long     expectedMaxBufferSize          = 1073741824;
            int      expectedMaxDepth       = 2147483647;
            TimeSpan expectedReceiveTimeout = TimeSpan.FromMinutes(10);
            TimeSpan expectedDefaultTimeout = TimeSpan.FromMinutes(1);
            BasicHttpSecurityMode          expectedSecurityMode = BasicHttpSecurityMode.TransportWithMessageCredential;
            BasicHttpMessageCredentialType clientCredType       = BasicHttpMessageCredentialType.Certificate;

            string xml = $@"
<configuration> 
    <system.serviceModel>         
        <bindings>         
            <basicHttpBinding>
                <binding name=""{expectedName}""
                         maxReceivedMessageSize=""{expectedMaxReceivedMessageSize}""
                         maxBufferSize=""{expectedMaxBufferSize}""
                         receiveTimeout=""00:10:00"">
                    <security mode=""{expectedSecurityMode}"">
                     <message clientCredentialType=""{clientCredType}"" />
                     </security>
                    <readerQuotas maxDepth=""{expectedMaxDepth}"" />   
                </binding >
            </basicHttpBinding>                             
        </bindings>                             
    </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                using (ServiceProvider provider = CreateProvider(fs.Name))
                {
                    IConfigurationHolder settingHolder = GetConfigurationHolder(provider);

                    var actualBinding = settingHolder.ResolveBinding(nameof(BasicHttpBinding), expectedName) as BasicHttpBinding;
                    Assert.Equal(expectedName, actualBinding.Name);
                    Assert.Equal(expectedMaxReceivedMessageSize, actualBinding.MaxReceivedMessageSize);
                    Assert.Equal(expectedMaxBufferSize, actualBinding.MaxBufferSize);
                    Assert.Equal(expectedDefaultTimeout, actualBinding.CloseTimeout);
                    Assert.Equal(expectedDefaultTimeout, actualBinding.OpenTimeout);
                    Assert.Equal(expectedDefaultTimeout, actualBinding.SendTimeout);
                    Assert.Equal(expectedReceiveTimeout, actualBinding.ReceiveTimeout);
                    Assert.Equal(TransferMode.Buffered, actualBinding.TransferMode);
                    Assert.Equal(expectedSecurityMode, actualBinding.Security.Mode);
                    Assert.Equal(clientCredType, actualBinding.Security.Message.ClientCredentialType);
                    Assert.Equal(expectedMaxDepth, actualBinding.ReaderQuotas.MaxDepth);
                }
            }
        }
Exemplo n.º 8
0
        public void BindingSection_WithBasicHttpBindingTest()
        {
            string   expectedName = "basicHttpBindingConfig";
            long     expectedMaxReceivedMessageSize = 1073741824;
            long     expectedMaxBufferSize          = 1073741824;
            int      expectedMaxDepth                  = 2147483647;
            TimeSpan expectedReceiveTimeout            = TimeSpan.FromMinutes(10);
            BasicHttpSecurityMode expectedSecurityMode = BasicHttpSecurityMode.TransportWithMessageCredential;

            string xml = $@"
<configuration>
    <configSections>
        <sectionGroup name=""system.serviceModel"" type=""CoreWCF.Configuration.ServiceModelSectionGroup, CoreWCF.ConfigurationManager"">
            <section name=""bindings"" type=""CoreWCF.Configuration.BindingsSection, CoreWCF.ConfigurationManager"" />
        </sectionGroup>         
    </configSections>  
    <system.serviceModel>         
        <bindings>         
            <basicHttpBinding>
                <binding name=""{expectedName}""
                         maxReceivedMessageSize=""{expectedMaxReceivedMessageSize}""
                         maxBufferSize=""{expectedMaxBufferSize}""
                         receiveTimeout=""{expectedReceiveTimeout}"">
                    <security mode=""{expectedSecurityMode}""/>      
                    <readerQuotas maxDepth=""{expectedMaxDepth}"" />
                </binding>
            </basicHttpBinding>           
        </bindings>                             
    </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                ServiceModelSectionGroup section = GetSectionFromXml(fs);

                BasicHttpBindingElement actualBinding = section.Bindings.BasicHttpBinding.Bindings.Cast <BasicHttpBindingElement>().First();

                Assert.Equal(expectedName, actualBinding.Name);
                Assert.Equal(expectedMaxReceivedMessageSize, actualBinding.MaxReceivedMessageSize);
                Assert.Equal(expectedMaxBufferSize, actualBinding.MaxBufferSize);
                Assert.Equal(expectedReceiveTimeout, actualBinding.ReceiveTimeout);
                Assert.Equal(expectedSecurityMode, actualBinding.Security.Mode);
                Assert.Equal(expectedMaxDepth, actualBinding.ReaderQuotas.MaxDepth);
            }
        }
Exemplo n.º 9
0
        public void ServiceSectionTest()
        {
            string expectedName1                = "AnotherService";
            string expectedName2                = "SomeService";
            string expectedBehavior             = "SomeServiceBehavior";
            string expectedBindingConfiguration = "netTcpBindingConfigService";
            string expectedContract             = "Server.Interface.SomeService";
            string expectedAddress              = "net.tcp://*****:*****@"
<configuration>
    <configSections>
        <sectionGroup name=""system.serviceModel"" type=""CoreWCF.Configuration.ServiceModelSectionGroup, CoreWCF.ConfigurationManager"">
            <section name=""services"" type=""CoreWCF.Configuration.ServicesSection, CoreWCF.ConfigurationManager"" />
        </sectionGroup>         
    </configSections>  
    <system.serviceModel>         
        <services>
            <service name=""{expectedName1}"" />
            <service name=""{expectedName2}""
                     behaviorConfiguration=""{expectedBehavior}"">
                <endpoint binding=""netTcpBinding""
                          bindingConfiguration=""{expectedBindingConfiguration}""
                          contract=""{expectedContract}""
                          address=""{expectedAddress}"" />  
            </service>   
        </services> 
    </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                ServiceModelSectionGroup section = GetSectionFromXml(fs);

                ServiceElement         firstService  = section.Services.Services.Cast <ServiceElement>().ElementAt(0);
                ServiceElement         secondService = section.Services.Services.Cast <ServiceElement>().ElementAt(1);
                ServiceEndpointElement endpoint      = secondService.Endpoints.Cast <ServiceEndpointElement>().Single();
                Assert.Equal(expectedName1, firstService.Name);
                Assert.Equal(expectedName2, secondService.Name);
                Assert.Equal(expectedBehavior, secondService.BehaviorConfiguration);
                Assert.Equal(expectedBindingConfiguration, endpoint.BindingConfiguration);
                Assert.Equal(expectedContract, endpoint.Contract);
                Assert.Equal(expectedAddress, endpoint.Address.OriginalString);
            }
        }
Exemplo n.º 10
0
        public void NetTcpBinding_WithDefaultSetting()
        {
            string   expectedName = "netTcpBindingConfig";
            long     expectedMaxReceivedMessageSize = 65536;
            long     expectedMaxBufferSize          = 65536;
            TimeSpan expectedReceiveTimeout         = TimeSpan.FromMinutes(10);
            TimeSpan expectedDefaultTimeout         = TimeSpan.FromMinutes(1);

            string xml = $@"
<configuration> 
    <system.serviceModel>         
        <bindings>         
            <netTcpBinding>
                <binding name=""{expectedName}""/>
            </netTcpBinding>                             
        </bindings>                             
   </system.serviceModel>
</configuration>";

            using (var fs = TemporaryFileStream.Create(xml))
            {
                using (ServiceProvider provider = CreateProvider(fs.Name))
                {
                    IConfigurationHolder settingHolder = GetConfigurationHolder(provider);

                    var actualBinding = settingHolder.ResolveBinding(nameof(NetTcpBinding), expectedName) as NetTcpBinding;
                    Assert.Equal(expectedName, actualBinding.Name);
                    Assert.Equal(expectedMaxReceivedMessageSize, actualBinding.MaxReceivedMessageSize);
                    Assert.Equal(expectedMaxBufferSize, actualBinding.MaxBufferSize);
                    Assert.Equal(expectedDefaultTimeout, actualBinding.CloseTimeout);
                    Assert.Equal(expectedDefaultTimeout, actualBinding.OpenTimeout);
                    Assert.Equal(expectedDefaultTimeout, actualBinding.SendTimeout);
                    Assert.Equal(expectedReceiveTimeout, actualBinding.ReceiveTimeout);
                    Assert.Equal(TransferMode.Buffered, actualBinding.TransferMode);
                    Assert.Equal(SecurityMode.Transport, actualBinding.Security.Mode);
                }
            }
        }