当前位置: 首页>>代码示例>>C#>>正文


C# InstanceContext类代码示例

本文整理汇总了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();
            }
        }
    }
开发者ID:SoumikMukherjeeDOTNET,项目名称:wcf,代码行数:32,代码来源:TypedProxyDuplexTests.cs

示例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);
        }
    }
开发者ID:noodlese,项目名称:wcf,代码行数:35,代码来源:WebSocketTests.cs

示例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);

        }
开发者ID:peelybird,项目名称:Glass.Sitecore.Mapper,代码行数:34,代码来源:SitecoreLinkedHandlerFixture.cs

示例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);
        }
    }
开发者ID:roncain,项目名称:wcf,代码行数:34,代码来源:DataContractTests.4.1.0.cs

示例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();
            }
        }
    }
开发者ID:dmetzgar,项目名称:wcf,代码行数:29,代码来源:WebSocketTests.cs

示例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);
                    }
                }

            }
        }
开发者ID:OpenSharp,项目名称:NDceRpc,代码行数:29,代码来源:SynchronizationTests.cs

示例7: AfterReceiveRequest

		public object AfterReceiveRequest (ref Message request, IClientChannel channel, InstanceContext instanceContext)
		{
			if (RequestReceived != null)
				return RequestReceived (ref request, channel, instanceContext);
			else
				return null;
		}
开发者ID:alesliehughes,项目名称:olive,代码行数:7,代码来源:InspectionBehaviors.cs

示例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();
            }
        }
    }
开发者ID:huoxudong125,项目名称:wcf,代码行数:33,代码来源:DuplexClientBaseTests.cs

示例9: Setup

 public void Setup()
 {
     _handler = new SitecoreFieldIEnumerableHandler();
     var context = new InstanceContext(
         new Dictionary<Type, SitecoreClassConfig>(),
         new AbstractSitecoreDataHandler[] { new SitecoreFieldIntegerHandler() });
     _service = new SitecoreService("master");
 }
开发者ID:peelybird,项目名称:Glass.Sitecore.Mapper,代码行数:8,代码来源:SitecoreFieldIEnumerableHandlerFixture.cs

示例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);
 }
开发者ID:TheLegion96,项目名称:fightthelandlord,代码行数:8,代码来源:DataCenterCallback.cs

示例11: GetInstance

        public object GetInstance(InstanceContext instanceContext, Message message)
        {
            if (instanceContext == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("instanceContext");
            }

            return instanceContext.Extensions.Find<DurableInstance>();
        }
开发者ID:krytht,项目名称:DotNetReferenceSource,代码行数:9,代码来源:DurableInstanceProvider.cs

示例12: GetInstance

        internal object GetInstance(InstanceContext instanceContext)
        {
            if (_provider == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR.SFxNoDefaultConstructor));
            }

            return _provider.GetInstance(instanceContext);
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:wcf,代码行数:9,代码来源:InstanceBehavior.cs

示例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(); 
     });
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:wcf,代码行数:10,代码来源:DuplexClientBaseTest.cs

示例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);
     });
 }
开发者ID:noodlese,项目名称:wcf,代码行数:10,代码来源:DuplexChannelFactoryTest.cs

示例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);
    }
开发者ID:weshaggard,项目名称:wcf,代码行数:11,代码来源:DuplexClientBaseTest.cs


注:本文中的InstanceContext类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。