@@ -20,9 +20,9 @@ public class XmlTransport : ITransport
2020 private const uint BatchSize = 100 ;
2121
2222 private readonly Uri endpoint ;
23+ private readonly HttpClient client ;
2324 private string username ;
2425 private string password ;
25- private Lazy < HttpClient > client = new Lazy < HttpClient > ( ( ) => new HttpClient ( ) ) ;
2626
2727 /// <summary>
2828 /// Initialize the transport with an alternate endpoint.
@@ -32,11 +32,25 @@ public class XmlTransport : ITransport
3232 /// <param name="username">The username assigned to the account on the given <paramref name="endpoint"/>.</param>
3333 /// <param name="password">The password assigned to the account on the given <paramref name="endpoint"/>.</param>
3434 /// <param name="endpoint">The alternate XML endpoint to use.</param>
35- public XmlTransport ( string username , string password , Uri endpoint )
35+ /// <param name="client">HttpClient used when sending xml</param>
36+ public XmlTransport ( string username , string password , Uri endpoint , HttpClient client )
3637 {
3738 this . username = username ;
3839 this . password = password ;
3940 this . endpoint = endpoint ;
41+ this . client = client ;
42+ }
43+
44+ /// <summary>
45+ /// Initialize the transport with an alternate endpoint.
46+ /// This is useful if for example Link Mobility has assigned you an account on the test system.
47+ /// Note that it must be an XML endpoint, not the SOAP or Simple HTTP endpoints that PSWin also provides.
48+ /// </summary>
49+ /// <param name="username">The username assigned to the account on the given <paramref name="endpoint"/>.</param>
50+ /// <param name="password">The password assigned to the account on the given <paramref name="endpoint"/>.</param>
51+ /// <param name="endpoint">The alternate XML endpoint to use.</param>
52+ public XmlTransport ( string username , string password , Uri endpoint ) : this ( username , password , endpoint , new HttpClient ( ) )
53+ {
4054 }
4155
4256 /// <summary>
@@ -72,7 +86,7 @@ private async Task<IEnumerable<MessageResult>> SendBatchAsync(Sms[] messageBatch
7286 Content = new StringContent ( payload . Declaration . ToString ( ) + payload . ToString ( ) , Encoding . UTF8 , "text/xml" ) ,
7387 } ;
7488
75- var response = await client . Value . SendAsync ( request ) ;
89+ var response = await client . SendAsync ( request ) ;
7690 if ( ! response . IsSuccessStatusCode )
7791 throw new SendMessageException ( $ "Sending failed because Gateway endpoint returned { ( int ) response . StatusCode } { response . ReasonPhrase } ") ;
7892
0 commit comments