Skip to content

Commit c8a8d7f

Browse files
Merge pull request #2 from PSWinCom/HttpMessageHandler-in-xmltransport
Make Client and XmTransport more testfriendly
2 parents 48e9a51 + 73956e4 commit c8a8d7f

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

PSWin.Client/LinkMobility.PSWin.Client.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
6-
<Version>1.1.0</Version>
6+
<Version>1.2.0</Version>
77
<Authors>Link Mobility NE</Authors>
88
<Company></Company>
99
<Description>Send SMS through PSWin gateway.</Description>

PSWin.Client/Transports/XmlTransport.cs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)