static void WcfTest() { int count = int.MaxValue; WcfHost <IHello, Hello> wcfHost = new WcfHost <IHello, Hello>(); wcfHost.StartHost(); IHello client = WcfClient.GetService <IHello>("http://127.0.0.1:14725"); client.SayHello("Hello"); Stopwatch watch = new Stopwatch(); watch.Start(); LoopHelper.Loop(1, () => { Task.Run(() => { LoopHelper.Loop(count, index => { var msg = client.SayHello("Hello" + index); Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:ffffff")}:{msg}"); }); }).Wait(); }); watch.Stop(); Console.WriteLine($"每次耗时:{(double)watch.ElapsedMilliseconds / count}ms"); }
private void Timer5_Elapsed(object sender, ElapsedEventArgs e) { this.timer5.Enabled = false; WcfClient <IFMSService> ws = new WcfClient <IFMSService>(); //try //{ lock (objLock) { FmsSamplingRecord record = new FmsSamplingRecord() { PKNO = CBaseData.NewGuid(), ASSET_CODE = "A20002", SAMPLING_TIME = DateTime.Now, TAG_SETTING_PKNO = "fe0e40d4bb57424088c1876bba50f229", TAG_VALUE_NAME = "测试", TAG_VALUE = (new Random()).Next(100).ToString(), CREATED_BY = CBaseData.LoginName, CREATION_DATE = DateTime.Now, REMARK = "", }; ws.UseService(s => s.AddFmsSamplingRecord(record)); } //} //catch (Exception ex) //{ // Console.WriteLine(ex.Message); //} Console.WriteLine($"3Thread Write{iWriteTest2++}"); this.timer5.Enabled = true; }
private void SaveCatalogOverService(List <Book> books) { var source = new WcfClient(ServiceAddress, ServicePort); SetLoadingState(true); ThreadPool.QueueUserWorkItem(_ => { try { if (!source.SaveBooks(books)) { MessageBox.Show(loc.CouldNotConnectToService, loc.Error, MessageBoxButton.OK); } } catch { //toDo: сделать вывод сообщения об ошибке } finally { SetLoadingState(false); } }); }
private void TestRemote(string fileName, string testsystem, List <string> lstBrowsers, List <string> testcases, List <string> languages) { using (WcfClient wcfClient = new WcfClient()) { wcfClient.TestRemote(fileName, testsystem, lstBrowsers, testcases, languages); } }
public RmRepairRecordView() { InitializeComponent(); _EAMClient = new WcfClient <IEAMService>(); Initialize(); }
/// <summary> /// To find if there are any active sessions /// </summary> /// <param name="dispatcher"></param> /// <returns></returns> public bool AreThereActiveSessions(string dispatcher) { using (var client = new WcfClient <ISessionDispatcher>(MessageTransferType.CompressedHttp, WcfService.SessionServer.GetHttpUri(dispatcher))) { return(client.Channel.AreThereActiveSessions()); } }
/// <summary> /// Heartbeat call to the server side. /// </summary> /// <param name="clientId">The client identifier.</param> public void Heartbeat(string clientId) { if (WcfClient != null) { WcfClient.Heartbeat(ClientId); } }
public PurviewEdit(SysPurview nm_SysPurview) { InitializeComponent(); _SDMService = new WcfClient <ISDMService>(); m_SysPurview = nm_SysPurview; this.DataContext = m_SysPurview; }
/// <summary> /// 按条件获取Tag点 /// 监控开启时直接获取内存的值,否则提取数据库的值 /// </summary> public static List <FmsAssetTagSetting> GetTagSettings(string sWhere) { #region 整理查询条件 if (string.IsNullOrEmpty(sWhere)) { sWhere = "USE_FLAG = 1"; } else { sWhere = "USE_FLAG = 1 AND " + sWhere; } #endregion if ((!bMonitor) || (_tagSettings == null)) //没有开启监控 || 空 { WcfClient <IFMSService> wsthis = new WcfClient <IFMSService>(); return(wsthis.UseService(s => s.GetFmsAssetTagSettings(sWhere))); //获取Tag配置点 } Expression <Func <FmsAssetTagSetting, bool> > whereLamda = SerializerHelper.ConvertParamWhereToLinq <FmsAssetTagSetting>(sWhere); return(_tagSettings.Where(whereLamda.Compile()).ToList()); }
protected override void GrantLock(Guid requestId, string resourceId) { LogTrace($"Request {requestId} given lock for {resourceId}. Attempting grant callback..."); // Check to make sure the callback is there - a race condition is possible where // the client cancels the request just after the resource grants it, but before it is notified. if (_callbacks.TryGetValue(requestId, out Uri callbackUri)) { using (var client = new WcfClient <ILockCallback>(MessageTransferType.Http, callbackUri)) { try { // Grant the lock via the callback channel, and add to the list of clients // that should be polled to make sure they are still alive. client.Channel.GrantLock(resourceId); _pollingClients.TryAdd(requestId, resourceId); LogTrace($"Granting lock for resource '{resourceId}' success."); } catch (Exception ex) { // Client could not be contacted - release the lock so it can be given to somebody else. LogError($"Granting lock for resource '{resourceId}' failed. Callback: {callbackUri}", ex); ReleaseLock(requestId); } } } else { LogWarn($"Callback for {requestId} was not found."); ReleaseLock(requestId); } }
private ServiceCommandOutput <object> CheckServiceConnectivity(string port, ServiceType type, ServiceSecurityMode mode) { var service = new WcfService <ICommandService <object>, DummyNativeCommandService>("localhost", ServiceName); service.AddBinding(BindingFactory.Create(new BindingConfiguration { Port = port, ServiceType = type })); if (mode == ServiceSecurityMode.BasicSSL) { var serviceSecurity = new ServiceSecurity { SecurityMode = ServiceSecurityMode.BasicSSL, CertificateConfiguration = _certificateConfiguration }; service.SetSecured(serviceSecurity); } service.Host(); var client = WcfClient <ICommandService <object> > .Create(type, "localhost", port, ServiceName, "api", mode); var output = client.Contract.ExecuteCommand("test", "token"); service.Stop(); return(output); }
static void WcfTest() { int threadCount = 4; int port = 9999; int count = 10000; int errorCount = 0; WcfHost <IHello, Hello> wcfHost = new WcfHost <IHello, Hello>(); wcfHost.StartHost(); IHello client = WcfClient.GetService <IHello>("http://127.0.0.1:14725"); client.SayHello("Hello"); Stopwatch watch = new Stopwatch(); List <Task> tasks = new List <Task>(); watch.Start(); LoopHelper.Loop(threadCount, () => { tasks.Add(Task.Run(() => { LoopHelper.Loop(count, index => { var msg = client.SayHello("Hello" + index); //Console.WriteLine($"{DateTime.Now.ToString("HH:mm:ss:ffffff")}:{msg}"); }); })); }); Task.WaitAll(tasks.ToArray()); watch.Stop(); Console.WriteLine($"并发数:{threadCount},运行:{count}次,每次耗时:{(double)watch.ElapsedMilliseconds / count}ms"); }
/// <summary> /// Stops Collection of Dart logs at the specified IP address. /// </summary> /// <param name="IP"></param> /// <returns></returns> public bool Stop(string IP) { using (var client = new WcfClient <IDartLogCollectorService>(MessageTransferType.Http, WcfService.CollectDartLogService.GetHttpUri(ServiceLocation))) { return(client.Channel.Stop(IP)); } }
/// <summary> /// Waits for the print job with the specified ID to be finished printing. /// </summary> /// <param name="server">The print server.</param> /// <param name="printJobId">The ID of the print job to wait for.</param> /// <param name="timeout">The amount of time to wait for the print job to be finished.</param> /// <returns><c>true</c> if the print job finished within the timeout, <c>false</c> otherwise.</returns> /// <exception cref="EndpointNotFoundException">The print monitor service is not running for the specified queue.</exception> public bool WaitForPrintJob(string server, Guid printJobId, TimeSpan timeout) { using (var client = new WcfClient <IPrintMonitorService>(MessageTransferType.Http, WcfService.PrintMonitor.GetHttpUri(server))) { return(client.Channel.WaitForPrintJobFinished(printJobId, timeout)); } }
private static Lazy <ServiceProxy> LoadFromConfig(ClientConfig config) { ClientContext.CreateNew(config); if (_commandServiceProxy == null) { var lazyConnection = new Lazy <ServiceProxy>(() => { var contextConfig = ClientContext.Current.Config; var client = WcfClient <ICommandService <object> > .Create(contextConfig.Runtime.Client.GetWcfServiceType(), contextConfig.Runtime.Client.Host, contextConfig.Runtime.Client.Port.ToString(CultureInfo.InvariantCulture), "CommandService"); client.OnFaulted += client_OnFaulted; CurrentContext.Default.Log.Info("Connection Established:" + client.ServerName + " Port:" + client.Port); return(new ServiceProxy(client.Contract, config)); }); _commandServiceProxy = lazyConnection; } return(_commandServiceProxy); }
/// <summary> /// Determines whether a new print job can be sent to the specified print queue without exceeding the specified number of jobs. /// </summary> /// <param name="server">The print server.</param> /// <param name="queue">The print queue.</param> /// <param name="maxJobsInQueue">The maximum number of jobs in the queue.</param> /// <returns><c>true</c> if the job can be submitted, <c>false</c> otherwise.</returns> /// <exception cref="EndpointNotFoundException">The print monitor service is not running for the specified queue.</exception> public bool RequestToSendPrintJob(string server, string queue, int maxJobsInQueue) { using (var client = new WcfClient <IPrintMonitorService>(MessageTransferType.Http, WcfService.PrintMonitor.GetHttpUri(server))) { return(client.Channel.RequestToSendJob(queue, maxJobsInQueue)); } }
public GoodsBarcodeInfo GetGoodsBarcodeInfo(string goodscode) { GoodsBarcodeInfo info; using (var client = new WcfClient <IService>(CMS_ENDPOINT)) { info = client.Call(e => e.GetGoodsBarcodeInfo(goodscode)); } if (info != null) { using (var client2 = new WcfClient <IKeedeAdmin>(KEEDE_ENDPOINT)) { var ids = new List <Guid> { info.GoodsId }; var priceDict = client2.Call(e => e.GetGoodsSellPrice(ids)); var originDict = client2.Call(e => e.GetGoodsAttrValues(ids, Configuration.AppSettings["MadeInIndex"].ToInt())); if ((priceDict != null) && priceDict.Count > 0) { info.SellPrice = priceDict.ContainsKey(info.GoodsId) ? priceDict[info.GoodsId] : "-"; } if ((originDict != null) && originDict.Count > 0) { info.Origin = originDict.ContainsKey(info.GoodsId) ? originDict[info.GoodsId] : string.Empty; } } } return(info); }
public IList <GoodsBarcodeInfo> GetGoodsBarcodeListByOutStock(string tradeNo) { IList <GoodsBarcodeInfo> list; using (var client = new WcfClient <IService>(CMS_ENDPOINT)) { list = client.Call(e => e.GetOutStockGoodsBarcode(tradeNo)); } if ((list != null) && (list.Count > 0)) { IDictionary <Guid, string> priceDict; IDictionary <Guid, string> originDict; using (var client2 = new WcfClient <IKeedeAdmin>(KEEDE_ENDPOINT)) { List <Guid> ids = (from ent in list select ent.GoodsId).Distinct <Guid>().ToList <Guid>(); priceDict = client2.Call(e => e.GetGoodsSellPrice(ids)); originDict = client2.Call(e => e.GetGoodsAttrValues(ids, Configuration.AppSettings["MadeInIndex"].ToInt())); } if (priceDict == null || originDict == null) { return(list); } foreach (GoodsBarcodeInfo info in list) { info.SellPrice = priceDict.ContainsKey(info.GoodsId) ? priceDict[info.GoodsId] : "-"; info.Origin = originDict.ContainsKey(info.GoodsId) ? originDict[info.GoodsId] : string.Empty; } } return(list); }
static void Main(string[] args) { /* * call service using static methods */ // call service method with return value var currentTime = WcfClient.RequestService <IWcfExampleService, DateTime>(service => service.GetCurrentDateTime()); Console.WriteLine("Current Time: {0}", currentTime); // call service method without return value WcfClient.RequestService <IWcfExampleService>(service => service.SayHello("Hello wcf!")); /* * call service using WcfClient object */ //var client = new WcfClient<IWcfExampleService>(new ProxyBuilder("WcfExampleService")); var client = WcfClient.Create <IWcfExampleService>(); // call service method with return value currentTime = client.RequestService <DateTime>(service => service.GetCurrentDateTime()); Console.WriteLine("Current Time: {0}", currentTime); // call service method without return value client.RequestService(service => service.SayHello("Hello again!")); Console.WriteLine("Press ENTER to exit..."); Console.ReadLine(); }
public void WcfClient_with_no_name_and_failed_connection_should_return_name_as_Unknown() { var failingChannel = TestChannel.Create(r => { throw new EndpointNotFoundException(); }); var subject = new WcfClient(failingChannel); Assert.That(subject.Name, Is.EqualTo("Unknown")); }
public static void FinishProcessPrepare(PmTaskLine taskLine, List <MesProcessCtrol> processCtrols) { WcfClient <IPLMService> wsPLM = new WcfClient <IPLMService>(); //计划 #region 更新任务状态 if (taskLine.RUN_STATE == 0) { taskLine.RUN_STATE = 1; taskLine.UPDATED_BY = CBaseData.LoginName; taskLine.LAST_UPDATE_DATE = DateTime.Now; wsPLM.UseService(s => s.UpdatePmTaskLine(taskLine)); } #endregion foreach (MesProcessCtrol process in processCtrols) { process.PKNO = CBaseData.NewGuid(); process.COMPANY_CODE = ""; process.CREATED_BY = CBaseData.LoginName; process.CREATION_DATE = DateTime.Now; process.USE_FLAG = 1; wsPLM.UseService(s => s.AddMesProcessCtrol(process)); } }
public AmPartsMasterNView() { InitializeComponent(); ws = new WcfClient <IEAMService>(); wsWMS = new WcfClient <IWMSService>(); GetPage(); }
private void CloseYTMusicUploader() { SetStatus($"Closing YT Music Uploader"); var wcfClient = new WcfClient("JBS_YTMusicUploader"); int sleepCount = 0; while (true) { try { wcfClient.Send("Close"); break; } catch { if (sleepCount > 7000) { break; } ThreadHelper.SafeSleep(50); sleepCount += 50; wcfClient = new WcfClient("JBS_YTMusicUploader"); } } }
private void btnSave_Click(object sender, RoutedEventArgs e) { _EAMClient = new WcfClient <IEAMService>(); if (IsNew) { try { m_AssetMaster = this.gridLayout.DataContext as AmAssetMasterN; m_AssetMaster.PKNO = Guid.NewGuid().ToString(); _EAMClient.UseService(s => s.AddAmAssetMasterN(m_AssetMaster)); } catch (Exception ex) { MessageUtil.ShowError(ex.Message); } } else { try { m_AssetMaster = this.gridLayout.DataContext as AmAssetMasterN; _EAMClient.UseService(s => s.UpdateAmAssetMasterN(m_AssetMaster)); } catch (Exception ex) { MessageUtil.ShowError(ex.Message); } } this.Close(); }
/// <summary> /// Calls Service Host to collect Logs /// </summary> /// <param name="device"></param> /// <param name="sessionID"></param> /// <param name="email"></param> public void CollectLog(string device, string sessionID, string email) { using (var client = new WcfClient <IDartLogCollectorService>(MessageTransferType.Http, WcfService.CollectDartLogService.GetHttpUri(ServiceLocation))) { client.Channel.CollectLog(device, sessionID, email); } }
public WcfCache() { string conn = ConfigurationManager.AppSettings["Smart:WcfCache"] ?? string.Format("{0}:9379", IPAddressUtility.GetLocalIPAddress()); this.cacheClient = new WcfClient <ICacheService>(string.Format("net.tcp://{0}", conn), null, null); this.cacheService = this.cacheClient.CreateService(); }
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { string filename = Server.MapPath("~/config/catclient.xml"); Cat.Initialize(filename); ITransaction t = Cat.GetProducer().NewTransaction("URL", "demo.aspx"); IMessageTree tree = Cat.GetManager().ThreadLocalMessageTree; //创建传递的上下文信息 HeaderContext context = new HeaderContext(); context.AppName = ""; context.CorrelationState = tree.MessageId; context.RootID = tree.RootMessageId == null ? tree.MessageId : tree.RootMessageId; context.ParentID = Cat.GetManager().CreateMessageId(); context.Ip = ""; HeaderOperater.SetClientWcfHeader(context); Cat.GetProducer().LogEvent("URL", "Call", "0", "Call Start..."); Cat.GetProducer().LogEvent("RemoteCall", "PigeonRequest", "0", context.ParentID); IUserBll bll = WcfClient.GetProxy <IUserBll>(); IList <User> list = bll.FindAll(); Cat.GetProducer().LogEvent("URL", "Call", "0", "Call End..."); //注:上下文信息必须在创建后清除 HeaderOperater.ClearClientWcfHeader(); t.Status = "A"; t.Complete(); this.GridView1.DataSource = list; this.GridView1.DataBind(); } }
/// <summary> /// 保存 自学习情况 /// </summary> public void Save() { if (string.IsNullOrEmpty(this.Text) || string.IsNullOrEmpty(this.Value) || (EnumType != 1)) //不自学习 { return; } ComboBoxItem select = SelectedItem as ComboBoxItem; if (select != null) //是选择的下拉框,则不需要自学习 { return; } try { if (ws == null) { ws = new WcfClient <ISDMService>(); } #region 照Value自学习 string sValue = "";//this.Value; string sName = this.Text; string sNO = this.Text; SysEnumItems item = new SysEnumItems() { PKNO = CBaseData.NewGuid(), COMPANY_CODE = "", CREATED_BY = CBaseData.LoginName, CREATION_DATE = DateTime.Now, LAST_UPDATE_DATE = DateTime.Now, //最后修改日期 ENUM_IDENTIFY = this.EnumIdentify, USE_FLAG = 1, ITEM_CODE = "", ITEM_NAME = sName, ITEM_NO = sNO, ITEM_INDEX = this.Items.Count, }; ws.UseService(s => s.AddSysEnumItems(item)); sValue = item.ITEM_NAME; ComboBoxItem comboBoxItem = new ComboBoxItem() { Content = this.Text, Tag = sValue, }; this.Items.Add(comboBoxItem); this.SelectedIndex = this.Items.Count - 1; this.SelectedItem = comboBoxItem; #endregion } catch (Exception ex) { // ignored Console.WriteLine("error:BasicItemCombox.Save " + ex.Message); } }
private void Initialize() { _SDMService = new WcfClient <ISDMService>(); List <SysMenuItem> m_SysMenuItems = _SDMService.UseService(s => s.GetSysMenuItems("TARGET_NAME = 'WPF'")).OrderBy(c => c.ITEM_SEQ).ToList(); this.treeList.ItemsSource = m_SysMenuItems; }
private void Initialize() { _SDMService = new WcfClient <ISDMService>(); List <SysDepartment> m_SysDepartment = _SDMService.UseService(s => s.GetSysDepartments("")); this.treeList.ItemsSource = m_SysDepartment; }