44namespace Microsoft . Azure . ServiceBus
55{
66 using System ;
7+ using System . Net ;
78 using System . Threading . Tasks ;
89 using Microsoft . Azure . Amqp ;
910 using Microsoft . Azure . Amqp . Framing ;
@@ -37,19 +38,43 @@ public ServiceBusConnection(ServiceBusConnectionStringBuilder connectionStringBu
3738 /// <param name="namespaceConnectionString">Namespace connection string</param>
3839 /// <remarks>It is the responsibility of the user to close the connection after use through <see cref="CloseAsync"/></remarks>
3940 public ServiceBusConnection ( string namespaceConnectionString )
40- : this ( namespaceConnectionString , Constants . DefaultOperationTimeout , RetryPolicy . Default )
41+ : this ( namespaceConnectionString , RetryPolicy . Default )
4142 {
4243 }
4344
45+ /// <summary>
46+ /// Creates a new connection to service bus.
47+ /// </summary>
48+ /// <param name="namespaceConnectionString">Namespace connection string.</param>
49+ /// <param name="retryPolicy">Retry policy for operations. Defaults to <see cref="RetryPolicy.Default"/></param>
50+ /// <remarks>It is the responsibility of the user to close the connection after use through <see cref="CloseAsync"/></remarks>
51+ public ServiceBusConnection ( string namespaceConnectionString , RetryPolicy retryPolicy = null )
52+ : this ( retryPolicy )
53+ {
54+ if ( string . IsNullOrWhiteSpace ( namespaceConnectionString ) )
55+ {
56+ throw Fx . Exception . ArgumentNullOrWhiteSpace ( nameof ( namespaceConnectionString ) ) ;
57+ }
58+
59+ var serviceBusConnectionStringBuilder = new ServiceBusConnectionStringBuilder ( namespaceConnectionString ) ;
60+ if ( ! string . IsNullOrWhiteSpace ( serviceBusConnectionStringBuilder . EntityPath ) )
61+ {
62+ throw Fx . Exception . Argument ( nameof ( namespaceConnectionString ) , "NamespaceConnectionString should not contain EntityPath." ) ;
63+ }
64+
65+ this . InitializeConnection ( serviceBusConnectionStringBuilder ) ;
66+ }
67+
4468 /// <summary>
4569 /// Creates a new connection to service bus.
4670 /// </summary>
4771 /// <param name="namespaceConnectionString">Namespace connection string.</param>
4872 /// <param name="operationTimeout">Duration after which individual operations will timeout.</param>
4973 /// <param name="retryPolicy">Retry policy for operations. Defaults to <see cref="RetryPolicy.Default"/></param>
5074 /// <remarks>It is the responsibility of the user to close the connection after use through <see cref="CloseAsync"/></remarks>
75+ [ Obsolete ( "This constructor is obsolete. Use ServiceBusConnection(string namespaceConnectionString, RetryPolicy retryPolicy) constructor instead, providing operationTimeout in the connection string." ) ]
5176 public ServiceBusConnection ( string namespaceConnectionString , TimeSpan operationTimeout , RetryPolicy retryPolicy = null )
52- : this ( operationTimeout , retryPolicy )
77+ : this ( retryPolicy )
5378 {
5479 if ( string . IsNullOrWhiteSpace ( namespaceConnectionString ) )
5580 {
@@ -63,6 +88,8 @@ public ServiceBusConnection(string namespaceConnectionString, TimeSpan operation
6388 }
6489
6590 this . InitializeConnection ( serviceBusConnectionStringBuilder ) ;
91+ // operationTimeout argument explicitly provided by caller should take precedence over OperationTimeout found in the connection string.
92+ this . OperationTimeout = operationTimeout ;
6693 }
6794
6895 /// <summary>
@@ -72,7 +99,7 @@ public ServiceBusConnection(string namespaceConnectionString, TimeSpan operation
7299 /// <param name="transportType">Transport type.</param>
73100 /// <param name="retryPolicy">Retry policy for operations. Defaults to <see cref="RetryPolicy.Default"/></param>
74101 public ServiceBusConnection ( string endpoint , TransportType transportType , RetryPolicy retryPolicy = null )
75- : this ( Constants . DefaultOperationTimeout , retryPolicy )
102+ : this ( retryPolicy )
76103 {
77104 if ( string . IsNullOrWhiteSpace ( endpoint ) )
78105 {
@@ -88,9 +115,8 @@ public ServiceBusConnection(string endpoint, TransportType transportType, RetryP
88115 this . InitializeConnection ( serviceBusConnectionStringBuilder ) ;
89116 }
90117
91- internal ServiceBusConnection ( TimeSpan operationTimeout , RetryPolicy retryPolicy = null )
118+ internal ServiceBusConnection ( RetryPolicy retryPolicy = null )
92119 {
93- this . OperationTimeout = operationTimeout ;
94120 this . RetryPolicy = retryPolicy ?? RetryPolicy . Default ;
95121 this . syncLock = new object ( ) ;
96122 }
@@ -193,6 +219,7 @@ void InitializeConnection(ServiceBusConnectionStringBuilder builder)
193219 this . TokenProvider = new SharedAccessSignatureTokenProvider ( builder . SasKeyName , builder . SasKey ) ;
194220 }
195221
222+ this . OperationTimeout = builder . OperationTimeout ;
196223 this . TransportType = builder . TransportType ;
197224 this . ConnectionManager = new FaultTolerantAmqpObject < AmqpConnection > ( this . CreateConnectionAsync , CloseConnection ) ;
198225 this . TransactionController = new FaultTolerantAmqpObject < Controller > ( this . CreateControllerAsync , CloseController ) ;
@@ -283,7 +310,8 @@ TransportSettings CreateTransportSettings()
283310 return AmqpConnectionHelper . CreateWebSocketTransportSettings (
284311 networkHost : networkHost ,
285312 hostName : hostName ,
286- port : port ) ;
313+ port : port ,
314+ proxy : WebRequest . DefaultWebProxy ) ;
287315 }
288316
289317 return AmqpConnectionHelper . CreateTcpTransportSettings (
0 commit comments