1

大家好,我在我的应用程序中面临一个 dualHttpBinding 和 webHttpBinding 问题。这是整体场景

我有一个使用 WCF 服务(具有三个不同的绑定)的 dotNet 和 Android 应用程序。

1. basicHttpBinding - For dotNet app (Service1.svc)
2. webHttpBinding - For Android to access via Rest full service (Service2.svc)
3. dualHttpBinding - For push notification to dotNet app(PushServie.svc)

当 android 应用程序使用 Servie2(AddOrderItems) 中的方法时,它会插入数据库,然后在 dotNet 应用程序中显示一条消息(推送通知)。为此,我在 PushService 中使用了 CallBackContract,当我尝试从 dotNet 应用程序(出于测试目的)访问 AddOrderItems 方法(在 Servie2 中)并且通知消息即将到来时,它工作正常。

但我的问题是我如何才能知道我的 AddOrderItems 是否以及何时从 android 应用程序调用,以便我必须在 dotNet 应用程序中显示一条消息(通过 CallBackContract)。

在调用 AddOrderItems 方法后,我尝试从 Servie2.svc 调用 PushServie.svc 方法(CallBackMessagge),但一点运气都没有。

这是Service2和PushService.svc的代码,

    // AddOrderItems method in IService2 which is implemented in Servie2.svc
    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "AddOrderItems", RequestFormat = 
    WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, 
    BodyStyle = WebMessageBodyStyle.Bare)]
    bool AddOrderItems(RequestOrderItemData orderItemData);

并在 IPushService 中回调方法,该方法在 PushService.svc 中实现

    [OperationContract(IsOneWay = true)]
    void DisplayMessage(int orderID, int tableID, string tableName);

这是 PushService 中 DisplayMessage 的代码

 IPushNotificationCallBack Callback
    {
        get
        {
            return  
            OperationContext.Current.GetCallbackChannel<IPushNotificationCallBack>();
        }
    }

以及 PushService.svc 中的方法

public void DisplayMessage(int orderID, int tableID, string tableName)
{
   Callback.DisplayMessage(orderID, tableID, tableName);
}

我试图在谷歌搜索,每个人都说 webHttpBindin 不支持回调功能。

我担心的是我想从 AddOrderItems 调用我的 DisplayMessage 方法。如果可以通过任何修改实现这一点,我真的很高兴。

据我认为我已经发布了所有必要的代码,如果还有其他需要,请告诉我,我会发布它。

任何帮助高度赞赏。

热烈的问候, Ganesh

4

0 回答 0