简体   繁体   中英

callback implementation with WWSAPI client and WCF service

I am learning WCF-WWSAPI and trying to develop the ICalculator example over TCP and duplex calls with an visual C++ client and C# on the service... Basically my client is program is trying to add 555 to the service number and the service will call the client to print the result on the screen through callback... client -> service dommunications works fine, my client can send values to the service calling AddTo function and it will work. But for any reason my client is not receiving the values to print out from the service...

this is what my client do:

hr = WsCreateMessageForChannel(
    threadInfo->channel,
    NULL, 
    0, 
    &message, 
    error);
if (FAILED(hr))
{
    PrintError(hr, error);
}

const WS_MESSAGE_DESCRIPTION* messageDescriptions[] = {
    // Result callback message
        &tempuri_org_wsdl.messages.ICalculatorDuplex_Equals_OutputCallbackMessage,      //<-- CHECK ON TEMPURI.ORG.WSDL.H
    // Equation callback message
        &tempuri_org_wsdl.messages.ICalculatorDuplex_Equation_OutputCallbackMessage     //<-- CHECK ON TEMPURI.ORG.WSDL.H
};
for (;;) // to receive all potential callback messages in an infinite loop
{
    void* callbackBody = NULL;
    ULONG index = 0;
    hr = WsReceiveMessage(
        threadInfo->channel,
        message,
        messageDescriptions,
        WsCountOf(messageDescriptions),
        WS_RECEIVE_OPTIONAL_MESSAGE,
        WS_READ_REQUIRED_POINTER,
        heap,
        callbackBody, <===this VALUE is 0x000000 from the server and I send an int
        sizeof(callbackBody),
        &index, // The returned index is used to determine which callback is received
        NULL,
        error);

This is my server constructor to pick up the callback:

public CalculatorService()
    {
        result = 0.0D;
        equation = result.ToString();
        callback = OperationContext.Current.GetCallbackChannel<ICalculatorDuplexCallback>();
    }

and this is my function on the contract with the callback:

public void AddTo(double n)
    {
        Console.WriteLine("Dentro de AddTo");
        result += n;
        equation += " + " + n.ToString();
        callback.Equals(result);
    }

any help/suggestion would be higly appreciated

thank you very much

Manuel

ok I got it!! this is the correct way to receive messages from the WCF service:

for (;;) // to receive all potential callback messages in an infinite loop
{
    void* callbackBody;
    ULONG index = 0;
    hr = WsReceiveMessage(
        threadInfo->channel,
        threadInfo->message,
        //&messageDescriptions[0],
        messageDescriptions,
        WsCountOf(messageDescriptions),
        WS_RECEIVE_OPTIONAL_MESSAGE,
        WS_READ_REQUIRED_POINTER,
        heap,
        &callbackBody,
        sizeof(callbackBody),
        &index,                     // The returned index is used to determine which callback is received
        NULL,
        error);

Now I can get the data as callback using WWSAPI and netTcpBinding!!!!

good for me!!!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM