gpt4 book ai didi

c++ - 使用 WWSAPI 客户端和 WCF 服务的回调实现

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:58:28 25 4
gpt4 key购买 nike

我正在学习 WCF-WWSAPI 并尝试开发 ICalculator example over TCP and duplex calls在服务上使用可视化 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>();
}

这是我在回调契约(Contract)上的功能:

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

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

非常感谢

曼纽尔

最佳答案

好的,我知道了!!这是从 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 获取数据作为回调!!!

对我有好处!!!

关于c++ - 使用 WWSAPI 客户端和 WCF 服务的回调实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13967597/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com