1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
// the connect code
void CdliClientDlg::OnBnClickedButtonConnect()
{
// Create a TCP duplex session channel
HRESULT hr;
WS_ERROR* pError = nullptr;
m_pChannel = nullptr;
m_pMessage = nullptr;
WS_ENDPOINT_ADDRESS address;
address.url.chars = L"net.tcp://localhost:14000/DLI";
address.url.length = (ULONG)::wcslen(address.url.chars);
address.headers = nullptr;
address.extensions = nullptr;
address.identity = nullptr;
hr = WsCreateError(NULL, 0, &pError);
if (FAILED(hr))
{
PrintError("WsCreateError()",hr,pError);
return;
}
hr = WsCreateChannel(WS_CHANNEL_TYPE_DUPLEX_SESSION,WS_TCP_CHANNEL_BINDING,NULL,0,NULL,&m_pChannel, pError);
if (FAILED(hr))
{
PrintError("WsCreateChannel()",hr,pError);
WsFreeError(pError);
return;
}
// Open channel to address
hr = WsOpenChannel(m_pChannel,&address,NULL,pError);
if (FAILED(hr))
{
PrintError("WsOpenChannel()",hr,pError);
WsFreeError(pError);
return;
}
// Create a thread to receive callback messages
HANDLE receiverThreadHandle = CreateThread(NULL, 0, StaticReceiverThread, (void*)this, 0, NULL);
if (receiverThreadHandle == NULL)
{
hr = HRESULT_FROM_WIN32(GetLastError());
PrintError("CreateThread()",hr,pError);
WsFreeError(pError);
return;
}
// subscribe for DLI data
hr = WsCreateMessageForChannel(m_pChannel,NULL,0,&m_pMessage,pError);
if (FAILED(hr))
{
PrintError("WsCreateMessageForChannel()",hr,pError);
WsFreeError(pError);
return;
}
_SubscribeDLIClient subscribeDLIClient = {L"MFCClient"};
hr = WsSendMessage(m_pChannel, m_pMessage, &my_dli_dliservice_wsdl.messages.IDliWcfContract_SubscribeDLIClient_InputMessage
,WS_WRITE_REQUIRED_VALUE, &subscribeDLIClient, sizeof(subscribeDLIClient), NULL, pError);
if (FAILED(hr))
{
PrintError("WsSendMessage()",hr,pError);
WsFreeError(pError);
return;
}
}
|