예제 #1
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"));
                }
            }
        }
예제 #2
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);
                }
            }
        }
예제 #3
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);
                }
            }
        }