2

我正在学习 WCF-WWSAPI 并尝试通过 TCP 开发 ICalculator 示例,并在服务上使用可视 C++ 客户端和 C# 进行双工调用...基本上我的客户端是程序正在尝试将 555 添加到服务号和服务将调用客户端通过回调在屏幕上打印结果...客户端-> 服务管理工作正常,我的客户端可以将值发送到调用 AddTo 函数的服务,它会工作。但是出于某种原因,我的客户没有收到要从服务中打印出来的值......

这就是我的客户所做的:

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);

这是我用来接收回调的服务器构造函数:

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

这是我在合同上的回调函数:

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

任何帮助/建议将不胜感激

非常感谢你

曼努埃尔

4

1 回答 1

0

好,我知道了!!这是从 WCF 服务接收消息的正确方法:

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);

现在我可以使用 WWSAPI 和 netTcpBinding 将数据作为回调获取!!!!

对我好!!!

于 2012-12-22T06:42:56.557 回答