private void OnSubmitOrder() { if (_currentOrder.CustomerId != Guid.Empty && _currentOrder.OrderItems.Count > 0) { GosServiceClient proxy = new GosServiceClient("NetTcpBinding_IGosService"); //GosProxy proxy = new GosProxy("NetTcpBinding_IGosService"); // this one to use handcoded proxy class just for example try { proxy.SubmitOrder(_currentOrder); MessageBox.Show("Order successfully saved"); CurrentOrder = new Order(); // reinitialize to empty order CurrentOrder.OrderDate = DateTime.Now; CurrentOrder.OrderStatusId = 1; Items = new ObservableCollection <OrderItemModel>(); } catch (Exception ex) { MessageBox.Show("Error saving order, please try again later. " + ex.Message); } finally { proxy.Close(); } } else { MessageBox.Show("Please select customer and add order items to submit an order"); } }
private async void LoadProductsAndCustomers() { // We use "automatic" implementation of service here (right click of project add service ref...) // Actualy we didn`t created Asyncs methods but they where genereted automatically // we can find GosServiceClient and async methods by the following: Sol.Expl. Show All Files // Open connected services -> under Reference.svcmap-> Reference.cs GosServiceClient proxy = new GosServiceClient("NetTcpBinding_IGosService"); // we are passing name of endpoint from App.config to the constructor //GosProxy proxy = new GosProxy("NetTcpBinding_IGosService"); // this one to use handcoded proxy class just for example #region security option 4 //proxy.ClientCredentials.Windows.ClientCredential.UserName = "******"; //proxy.ClientCredentials.Windows.ClientCredential.Domain = ... in case different domains //proxy.ClientCredentials.Windows.ClientCredential.Password = "******"; #endregion #region security tip // with NTLM (workgroup config) we have to duplicate the username and pasworrd that`s configured on the client machine, // on the server machine as well. In a domain config, all that`s handled by ActiveDirectory #endregion try { Products = await proxy.GetProductsAsync(); Customers = await proxy.GetCustomerAsync(); } catch (Exception ex) { MessageBox.Show("Failed to load server data. " + ex.Message); } finally { proxy.Close(); } }