本文整理汇总了C#中InstanceContext类的典型用法代码示例。如果您正苦于以下问题:C# InstanceContext类的具体用法?C# InstanceContext怎么用?C# InstanceContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
InstanceContext类属于命名空间,在下文中一共展示了InstanceContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ServiceContract_TypedProxy_AsyncTask_CallbackReturn
public static void ServiceContract_TypedProxy_AsyncTask_CallbackReturn()
{
DuplexChannelFactory<IWcfDuplexTaskReturnService> factory = null;
Guid guid = Guid.NewGuid();
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.None;
DuplexTaskReturnServiceCallback callbackService = new DuplexTaskReturnServiceCallback();
InstanceContext context = new InstanceContext(callbackService);
try
{
factory = new DuplexChannelFactory<IWcfDuplexTaskReturnService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_TaskReturn_Address));
IWcfDuplexTaskReturnService serviceProxy = factory.CreateChannel();
Task<Guid> task = serviceProxy.Ping(guid);
Guid returnedGuid = task.Result;
Assert.Equal(guid, returnedGuid);
factory.Close();
}
finally
{
if (factory != null && factory.State != CommunicationState.Closed)
{
factory.Abort();
}
}
}
示例2: RequestResponseOverWebSocketManually_Echo_RoundTrips_Guid
public static void RequestResponseOverWebSocketManually_Echo_RoundTrips_Guid()
{
DuplexChannelFactory<IWcfDuplexService> factory = null;
IWcfDuplexService duplexProxy = null;
Guid guid = Guid.NewGuid();
try
{
// *** SETUP *** \\
NetHttpBinding binding = new NetHttpBinding();
binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback();
InstanceContext context = new InstanceContext(callbackService);
factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.NetHttpWebSocketTransport_Address));
duplexProxy = factory.CreateChannel();
// *** EXECUTE *** \\
Task.Run(() => duplexProxy.Ping(guid));
Guid returnedGuid = callbackService.CallbackGuid;
// *** VALIDATE *** \\
Assert.True(guid == returnedGuid, string.Format("The sent GUID does not match the returned GUID. Sent '{0}', Received: '{1}'", guid, returnedGuid));
// *** CLEANUP *** \\
factory.Close();
((ICommunicationObject)duplexProxy).Close();
}
finally
{
// *** ENSURE CLEANUP *** \\
ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)duplexProxy, factory);
}
}
示例3: Setup
public void Setup()
{
_handler = new SitecoreLinkedHandler();
_database = global::Sitecore.Configuration.Factory.GetDatabase("master");
_target = _database.GetItem("/sitecore/content/Glass/ItemLinksTest");
SitecoreProperty idProperty = new SitecoreProperty(){
Attribute = new SitecoreIdAttribute(),
Property = typeof(SitecoreLinkedHandlerFixtureNS.LinkedTestClass).GetProperty("Id")
};
SitecoreIdDataHandler idHandler = new SitecoreIdDataHandler();
idHandler.ConfigureDataHandler(idProperty);
var context = new InstanceContext(
(new SitecoreClassConfig[]{
new SitecoreClassConfig(){
ClassAttribute = new SitecoreClassAttribute(),
Properties = new SitecoreProperty[]{
idProperty
},
Type = typeof(SitecoreLinkedHandlerFixtureNS.LinkedTestClass),
DataHandlers = new AbstractSitecoreDataHandler []{
idHandler
}
}
}).ToDictionary(), new AbstractSitecoreDataHandler[] { });
_service = new SitecoreService(_database, context);
}
示例4: NetTcpBinding_DuplexCallback_ReturnsXmlComplexType
public static void NetTcpBinding_DuplexCallback_ReturnsXmlComplexType()
{
DuplexChannelFactory<IWcfDuplexService_Xml> factory = null;
NetTcpBinding binding = null;
WcfDuplexServiceCallback callbackService = null;
InstanceContext context = null;
IWcfDuplexService_Xml serviceProxy = null;
Guid guid = Guid.NewGuid();
try
{
binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.None;
callbackService = new WcfDuplexServiceCallback();
context = new InstanceContext(callbackService);
factory = new DuplexChannelFactory<IWcfDuplexService_Xml>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_XmlDuplexCallback_Address));
serviceProxy = factory.CreateChannel();
serviceProxy.Ping_Xml(guid);
XmlCompositeTypeDuplexCallbackOnly returnedType = callbackService.XmlCallbackGuid;
// validate response
Assert.True((guid.ToString() == returnedType.StringValue), String.Format("The Guid to string value sent was not the same as what was returned.\nSent: {0}\nReturned: {1}", guid.ToString(), returnedType.StringValue));
((ICommunicationObject)serviceProxy).Close();
factory.Close();
}
finally
{
ScenarioTestHelpers.CloseCommunicationObjects((ICommunicationObject)serviceProxy, factory);
}
}
示例5: RequestResponseOverWebSocketManually_Echo_RoundTrips_Guid
public static void RequestResponseOverWebSocketManually_Echo_RoundTrips_Guid()
{
DuplexChannelFactory<IWcfDuplexService> factory = null;
Guid guid = Guid.NewGuid();
NetHttpBinding binding = new NetHttpBinding();
binding.WebSocketSettings.TransportUsage = WebSocketTransportUsage.Always;
WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback();
InstanceContext context = new InstanceContext(callbackService);
try
{
factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.NetHttpWebSocketTransport_Address));
IWcfDuplexService duplexProxy = factory.CreateChannel();
Task.Run(() => duplexProxy.Ping(guid));
Guid returnedGuid = callbackService.CallbackGuid;
Assert.True(guid == returnedGuid, string.Format("The sent GUID does not match the returned GUID. Sent '{0}', Received: '{1}'", guid, returnedGuid));
}
finally
{
if (factory != null && factory.State != CommunicationState.Closed)
{
factory.Abort();
}
}
}
示例6: CallbackToSyncContext
public void CallbackToSyncContext()
{
var path = @"net.pipe://127.0.0.1/" + this.GetType().Name + MethodBase.GetCurrentMethod().Name;
var binding = new NetNamedPipeBinding() { MaxConnections = 5 };
using (var server = new ServiceHost(new SyncCallbackService(), new Uri(path)))
{
server.AddServiceEndpoint(typeof(ISyncCallbackService), binding, path);
server.Open();
using (var syncContext = new StaSynchronizationContext())
{
InstanceContext context = null;
NDceRpc.ServiceModel.DuplexChannelFactory<ISyncCallbackService> channelFactory = null;
ISyncCallbackService client = null;
syncContext.Send(_ => SynchronizationContext.SetSynchronizationContext(syncContext), null);
syncContext.Send(_ => context = new InstanceContext(new SyncCallbackServiceCallback()), null);
syncContext.Send(_ => channelFactory = new NDceRpc.ServiceModel.DuplexChannelFactory<ISyncCallbackService>(context, binding),null);
syncContext.Send(_ => client = channelFactory.CreateChannel(new EndpointAddress(path)),null);
using (channelFactory)
{
var callbackThread = client.Call();
Assert.AreEqual(syncContext.ManagedThreadId, callbackThread);
}
}
}
}
示例7: AfterReceiveRequest
public object AfterReceiveRequest (ref Message request, IClientChannel channel, InstanceContext instanceContext)
{
if (RequestReceived != null)
return RequestReceived (ref request, channel, instanceContext);
else
return null;
}
示例8: DuplexClientBaseOfT_OverNetTcp_Synchronous_Call
public static void DuplexClientBaseOfT_OverNetTcp_Synchronous_Call()
{
DuplexClientBase<IWcfDuplexService> duplexService = null;
Guid guid = Guid.NewGuid();
try
{
NetTcpBinding binding = new NetTcpBinding();
binding.Security.Mode = SecurityMode.None;
WcfDuplexServiceCallback callbackService = new WcfDuplexServiceCallback();
InstanceContext context = new InstanceContext(callbackService);
duplexService = new MyDuplexClientBase<IWcfDuplexService>(context, binding, new EndpointAddress(Endpoints.Tcp_NoSecurity_Callback_Address));
IWcfDuplexService proxy = duplexService.ChannelFactory.CreateChannel();
// Ping on another thread.
Task.Run(() => proxy.Ping(guid));
Guid returnedGuid = callbackService.CallbackGuid;
Assert.True(guid == returnedGuid,
string.Format("The sent GUID does not match the returned GUID. Sent '{0}', Received: '{1}'", guid, returnedGuid));
((ICommunicationObject)duplexService).Close();
}
finally
{
if (duplexService != null && duplexService.State != CommunicationState.Closed)
{
duplexService.Abort();
}
}
}
示例9: Setup
public void Setup()
{
_handler = new SitecoreFieldIEnumerableHandler();
var context = new InstanceContext(
new Dictionary<Type, SitecoreClassConfig>(),
new AbstractSitecoreDataHandler[] { new SitecoreFieldIntegerHandler() });
_service = new SitecoreService("master");
}
示例10: ContactCenterCallback
public ContactCenterCallback(IContactCenterCallbackHandler handler)
{
this._handler = handler;
InstanceContext site = new InstanceContext(this);
this._proxy = new ContactCenterProxy(site);
handler.ContactCenterProxy = this._proxy;
this._proxy.BeginJoin(handler.ServiceID, new AsyncCallback(OnEndJoin), null);
}
示例11: GetInstance
public object GetInstance(InstanceContext instanceContext, Message message)
{
if (instanceContext == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("instanceContext");
}
return instanceContext.Extensions.Find<DurableInstance>();
}
示例12: GetInstance
internal object GetInstance(InstanceContext instanceContext)
{
if (_provider == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxNoDefaultConstructor));
}
return _provider.GetInstance(instanceContext);
}
示例13: CreateDuplexClientBase_Binding_Url_Mismatch_Throws
public static void CreateDuplexClientBase_Binding_Url_Mismatch_Throws()
{
InstanceContext context = new InstanceContext(new WcfDuplexServiceCallback());
Binding binding = new NetTcpBinding();
EndpointAddress endpoint = new EndpointAddress(FakeAddress.HttpAddress);
Assert.Throws<ArgumentException>("via", () => {
MyDuplexClientBase<IWcfDuplexService> duplexClientBase = new MyDuplexClientBase<IWcfDuplexService>(context, binding, endpoint);
((ICommunicationObject)duplexClientBase).Open();
});
}
示例14: CreateChannel_EmptyEndpointAddress_AsString_ThrowsUriFormat
public static void CreateChannel_EmptyEndpointAddress_AsString_ThrowsUriFormat()
{
WcfDuplexServiceCallback callback = new WcfDuplexServiceCallback();
InstanceContext context = new InstanceContext(callback);
Binding binding = new NetTcpBinding();
Assert.Throws<UriFormatException>(() =>
{
DuplexChannelFactory<IWcfDuplexService> factory = new DuplexChannelFactory<IWcfDuplexService>(context, binding, string.Empty);
});
}
示例15: DuplexClientBase_Aborts_Changes_CommunicationState
public static void DuplexClientBase_Aborts_Changes_CommunicationState()
{
InstanceContext context = new InstanceContext(new WcfDuplexServiceCallback());
Binding binding = new NetTcpBinding();
EndpointAddress endpoint = new EndpointAddress(FakeAddress.TcpAddress);
MyDuplexClientBase<IWcfDuplexService> duplexClientBase = new MyDuplexClientBase<IWcfDuplexService>(context, binding, endpoint);
Assert.Equal<CommunicationState>(CommunicationState.Created, duplexClientBase.State);
duplexClientBase.Abort();
Assert.Equal<CommunicationState>(CommunicationState.Closed, duplexClientBase.State);
}