netTcpBinding을 사용하여 WCF 콜백 서비스를 만들려고합니다. 나는에게 피난처를 나는이 문제를 해결하기위한 인터넷을 검색 한 svcutil.exe에 사용하는 대신 서비스 참조를 추가 한WCF 서비스를 호출 할 때 System.InvalidOperationException
An unhandled exception of type 'System.InvalidOperationException' occurred in System.ServiceModel.dll
Additional information: The InstanceContext provided to the ChannelFactory contains a UserObject that does not implement the CallbackContractType 'Client.WCFService.IHostFunctionsCallback'.
:하지만, 나는 예외 다음 얻을 서비스의 메소드를 호출 할 때 아직 해결책을 찾지 못했습니다. 여기
내 구현의 :IHostFunctions.cs (HostLibrary의 일부)
using System.ServiceModel;
namespace HostLibrary
{
[ServiceContract(CallbackContract = typeof(ICallback))]
public interface IHostFunctions
{
[OperationContract]
void OpenSession();
}
}
ICallback.cs (HostLibrary의 일부)
using System.ServiceModel;
namespace HostLibrary
{
public interface ICallback
{
[OperationContract]
void OnCallback();
}
}
HostFunctions.cs (HostLibrary의 일부)
using System;
using System.ServiceModel;
using System.Timers;
namespace HostLibrary
{
[ServiceBehavior(ConcurrencyMode = ConcurrencyMode.Multiple)]
public class HostFunctions : IHostFunctions
{
#region Implementation of IHostFunctions
public static ICallback Callback;
public static Timer Timer;
public void OpenSession()
{
Console.WriteLine("> Session opened at {0}", DateTime.Now);
Callback = OperationContext.Current.GetCallbackChannel<ICallback>();
Timer = new Timer(1000);
Timer.Elapsed += OnTimerElapsed;
Timer.Enabled = true;
}
void OnTimerElapsed(object sender, ElapsedEventArgs e)
{
Callback.OnCallback();
}
#endregion
}
}
Callback.cs (클라이언트의 일부) 서비스
using System;
using System.Globalization;
using System.ServiceModel;
using System.Threading;
using Client.WCFService;
namespace Client
{
internal class Program
{
private static void Main(string[] args)
{
var callback = new Callback();
using (var proxy = new HostFunctionsClient(new InstanceContext(callback)))
{
proxy.OpenSession();
}
Console.ReadLine();
}
}
}
코드는 http://adamprescott.net/2012/08/15/a-simple-wcf-service-callback-example/ 만에에서있는 클라이언트의
using System;
using System.ServiceModel;
using HostLibrary;
namespace WCF_TCP_Callbacks
{
internal static class Program
{
private static void Main(string[] args)
{
using (var sh = new ServiceHost(typeof (HostFunctions)))
{
sh.Open();
Console.WriteLine("Service started.");
Console.ReadLine();
Console.WriteLine("Stopping service...");
sh.Close();
}
}
}
}
Program.cs의
using System;
using HostLibrary;
namespace Client
{
public class Callback : ICallback
{
#region Implementation of ICallback
public void OnCallback()
{
Console.WriteLine("> Received callback at {0}", DateTime.Now);
}
#endregion
}
}
Program.cs netTcpBinding.
나는 이미 첫 번째 블로그 게시물을 읽었지만, 불행히도 CallbackBehavior를 추가하면 여전히 예외가 발생합니다. –
기본적으로 netTCPBinding에서 문제가 발생하기 때문에 nettcpbinding을 사용하여 http://stackoverflow.com/questions/4534923/duplex-communication-using-nettcpbinding-contractfilter-mismatch를 시도해야합니다. –
불행히도 여전히 작동하지 않습니다 ... –