Hej,
mam dwa pytania do kodu poniżej:
- czy _messageRepository przenieść do serwisu i do tegoż serwisu przekazać List<Message> tak by metoda SendSms wywoływała tylko serwis?
- drugie wywołanie ( druga iteracja )
var response = client.PostAsync(API_URL, httpContent).Result;
nie przechodzi nawet do sprawdzenia warunku if i dostaję gdzieś w debugu
"Żądanie zostało przerwane Nie można utworzyć bezpiecznego kanału SSL/TLS"
public class MessageService
{
public IEnumerable<Message> _message;
private readonly IMessageRepository _messageRepository;
private readonly ISerwerSMSService _serwerSMSService;
public MessageService(IMessageRepository messageRepository, ISerwerSMSService serwerSMSService)
{
_messageRepository = messageRepository;
_serwerSMSService = serwerSMSService;
}
public void SendSms()
{
_message = _messageRepository.GetByStatus(status.inQueue);
foreach (Message m in _message)
{
var res = _serwerSMSService.Send(m);
}
}
}
SerwerSmsService
public class SerwerSMSService : ISerwerSMSService
{
public static readonly string API_URL = "https://api1.serwersms.pl/zdalnie/";
public Dictionary<string, string> _content = new Dictionary<string, string>();
public SerwerSMSService()
{
_content = Extensions.GetSmsApiConfiguration.GetConfig();
}
public async Task Send(Message message)
{
using (var client = new HttpClient())
{
_content.Add("wiadomosc", message.MessageBody);
_content.Add("numer", message.Phone);
_content.Add("akcja", "wyslij_sms");
var httpContent = new FormUrlEncodedContent(_content);
var response = client.PostAsync(API_URL, httpContent).Result;
if (response.IsSuccessStatusCode)
{
var responseContent = response.Content;
string responseString = responseContent.ReadAsStringAsync().Result;
}
}
}
}