UssdSession.SendMessageAndGetReplyAsync(UssdMessage) Method

Definition

Sends a message to a USSD session and returns a handler to retrieve the reply asynchronously.

Note

This functionality is available only to mobile operator apps and UWP apps given privileged access by mobile network operators.

If you want to use this API and publish your app to the Microsoft Store, then you'll need special approval. For more information, see the Restricted capabilities section in the App capability declarations topic.

public:
 virtual IAsyncOperation<UssdReply ^> ^ SendMessageAndGetReplyAsync(UssdMessage ^ message) = SendMessageAndGetReplyAsync;
IAsyncOperation<UssdReply> SendMessageAndGetReplyAsync(UssdMessage const& message);
public IAsyncOperation<UssdReply> SendMessageAndGetReplyAsync(UssdMessage message);
function sendMessageAndGetReplyAsync(message)
Public Function SendMessageAndGetReplyAsync (message As UssdMessage) As IAsyncOperation(Of UssdReply)

Parameters

message
UssdMessage

The message to send to the USSD session.

Returns

An asynchronous handler to retrieve the USSD response to the sent message.

Windows requirements

App capabilities
cellularDeviceControl cellularDeviceIdentity

Remarks

The USSD message being sent can be either a request or a response. The operation is asynchronous and issues a single callback using the IAsyncOperation(UssdReply) interface upon completion. You can cancel the asynchronous operation using the IAsyncOperation(UssdReply) interface.

When an application using the C++ projection of SendMessageAndGetReplyAsync releases its last reference to the UssdSession object from within that callback, SendMessageAndGetReplyAsync may hang. Therefore, applications must ensure that the callback is not released from within SendMessageAndGetReplyAsync. One way of doing this is to create another asynchronous operation (for example, a timer) from within the callback whose completion callback is used to release the session object by passing it a reference to the session object.

#include <winrt/Windows.System.Threading.h>
using namespace winrt;
using namespace Windows::System::Threading;
...
auto timerDelegate = [ussdSession](ThreadPoolTimer const& timer) {};
Windows::Foundation::TimeSpan delay{ std::chrono::seconds(1) };
ThreadPoolTimer timer{ ThreadPoolTimer::CreateTimer(TimerElapsedHandler(timerDelegate), delay) };
auto timerDelegate = [ussdSession](Windows::System::Threading::ThreadPoolTimer^ timer) {};
Windows::Foundation::TimeSpan delay;
delay.Duration = 1; // non-zero value
Windows::System::Threading::ThreadPoolTimer^ timer = 
Windows::System::Threading::ThreadPoolTimer::CreateTimer(ref new
Windows::System::Threading::TimerElapsedHandler(timerDelegate), delay);

Applies to