【发布时间】:2015-01-23 09:21:59
【问题描述】:
您好,我有一个服务看起来像这样。
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Multiple, UseSynchronizationContext = false)]
public class Service : IService
{
public string test(string value)
{
IServiceCallBack callback = OperationContext.Current.GetCallbackChannel<IServiceCallBack>();
callback.callBackTest("callBack response");
return value + ", normal response";
}
}
[ServiceContract(CallbackContract = typeof(IServiceCallBack))]
public interface IService
{
[OperationContract]
[WebInvoke(
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
Method = "POST")]
string test(string value);
}
public interface IServiceCallBack
{
[OperationContract]
void callBackTest(string value);
}
现在我的需要是两个不同的绑定将使用相同的服务(如果可能的话)我知道我可以创建两个完整的单独服务来使其工作,但我宁愿不这样做,因为这两个绑定将使用相同的功能
我的情况是我们有一些客户端是苹果设备,它们将使用WebHttpBinding
以及将使用NetTcpBinding的Windows客户端
现在我希望 Windows 客户端能够使用回调,但对于苹果设备我只想忽略回调。
如果我尝试使用 WebHttpBinding 托管服务,我会收到此错误
base = {"Contract requires Duplex,
but Binding 'WebHttpBinding' doesn't
support it or isn't configured properly to support it."}
对我来说,这意味着它不会工作,但可以配置为工作? 或者他们是否意味着我必须配置和删除我的回调才能让它工作?
那么是否可以忽略WebHttpBinding 的回调而只接收正常响应?
【问题讨论】:
-
HTTP 本质上不是双工的 - WCF 中唯一的双工 HTTP 绑定是
DualWsHttpBinding。我认为在这种情况下,最简单的方法是创建两个服务,一个实现回调,一个不实现。
标签: c# wcf callback duplex webhttpbinding