WCF WebService的 - 有没有一种方法,以确定该客户端收到的响应? [英] WCF WebService - Is there a way to determine that client received response?

查看:150
本文介绍了WCF WebService的 - 有没有一种方法,以确定该客户端收到的响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以说我有一个客户端可以使用一些服务器端消息队列中接收消息的WCF服务。作为一个例子,可以说有电子邮件在数据表中的服务器端的队列:

Lets say I have a WCF service that a client can use to receive message from some server side message queue. As an example, lets say there is a server-side queue of email in a data table:

ID | MESSAGE_TEXT | SENT
------------------------
1  | Hi!          | N
2  | A 2nd Msg    | N

让我们定义我们的服务为:

Lets define our service as:

[OperationContract]
public List<string> GetMessages()
{
    var messages = LoadMessagesFromDb();
    var messageText = (from m in messages select m.MessageText).ToArray();
    return messageText;
}

让我们假设LoadMessagesFromDb()只是抓住所有的消息,其中SENT ='N'。因此,我们的加载,然后提取所有的文本字符串,返回他们。

Lets assume that LoadMessagesFromDb() just grabs all the messages where SENT = 'N'. So we load those, and then extract all the text strings and return them.

现在我在这里的问题是,我真的很需要标记这些邮件在我的数据表发送='Y'。我可以做这样的事情:

Now my issue here is that I really need to mark those messages as "sent = 'Y'" in my data table. I could do something like:

[OperationContract]
public List<string> GetMessages()
{
    var messages = LoadMessagesFromDb();
    var messageText = (from m in messages select m.MessageText).ToArray();

    // mark sent
    foreach(var msg in messages)
        MarkSentInDb(msg.ID);

    return messageText;
}

如果在将数据返回给客户端的错误

不过,会发生什么?可能是连接问题,还是一个WCF序列化的问题?我真正想要做的是某种程度上知道,客户端收到该邮件成功。我唯一​​能想到的,现在是让第2方法,客户端可以调用,表明项目是成功接收:

However, what happens if there is an error in returning the data to the client? Possibly a connectivity issue, or a WCF serialization issue? What I'd really like to do is somehow know that the client received the message successfully. The only thing I can think of right now is make a 2nd method that the client can call to indicate that the items were received successfully:

[DataContract]
public class Message
{
    [DataMember]
    public long ID { get; set; }

    [DataMemeber]
    public string Text { get; set; }
}

然后对业务的第二个方法:

then have a 2nd method on the service:

[OperationContract]
public List<Message> GetMessages();

[OperationContract]
public void ConfirmMessagesReceived(List<long> messageIds);

所以客户必须所有ID发回给我。有没有更好的办法做到这一点?如果我是在ASP.NET,而不是WCF这样做,我可以有方法打开响应流和回写数据,并在一个try / catch,但我似乎并没有在WCF同样的灵活性,未做一堆自定义消息的作家和扩展......任何人都有一个更好的主意如何分辨是否有发射过程中发生错误返回给客户端?请问WS-ReliableMessaging的给我什么?

So the client would have to send all the IDs back to me. Is there a better way to do this? If I were doing this in ASP.NET instead of WCF, I could have the method open the response stream and write back the data, and have that in a try/catch, but I don't seem to have the same flexibility in WCF, without making a bunch of custom message writers and extensions... Anyone have a better idea how to tell if there is an error during transmit back to the client? Does ws-reliablemessaging give me anything?

推荐答案

ReliableSessions (可与WsHttpBinding的)将透明地确保您的邮件在传输层错误的情况下,收到的客户端。在客户端上的串行化层错误将必须被处理那里

ReliableSessions (available with the WsHttpBinding) would transparently ensure that your messages are received by the client in the case of transport-level errors. Errors in the serialization layer on the client side would have to be handled there.

如果您在客户端需要更多的确认,你可以实现一个双工服务(使用的 WsDualHttpBinding )的合同,很容易沟通返回到客户端的服务器。

If you needed more acknowledgment from the client, you could implement a duplex service (using the WsDualHttpBinding) contract to easily communicate back to the server from the client.

这篇关于WCF WebService的 - 有没有一种方法,以确定该客户端收到的响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆