Пример #1
0
        public ServiceJSONResult MyMethod(ServiceJSONInput input)
        {
            //controls if input data is not null, otherwise it returns
            if (input == null)
            {
                return(new ServiceJSONResult {
                    Customer = null, Exception = new Exception("Invalid input data"), Message = "Sevice Cannnot perform your request"
                });
            }

            //defines a ret var
            ServiceJSONResult ret = new ServiceJSONResult {
                Customer = input.Customer, Exception = null
            };

            try{
                //do something with input data
                ret.Message = "Your request has been performed";
            }
            catch (Exception ex) {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                ret.Exception = new Exception(ex.Message);
                ret.Message   = "Sevice Cannnot perform your request";
            }

            return(ret);
        }
Пример #2
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            ServiceJSONClient MyClient = ConfigureClientProxy();

            MyClient.Open();
            MyClient.MyMethodCompleted += new EventHandler <MyMethodCompletedEventArgs>(MyMethodCompleted);


            ServiceJSONInput InputData = new ServiceJSONInput {
                Customer = new Customer {
                    FirstName = "Steve",
                    LastName  = "Jobs"
                },
                Account = new Account {
                    UserName = "******",
                    Password = "******"
                }
            };

            MyClient.MyMethodAsync(InputData);
        }
Пример #3
0
        public void Call_MyMethod_With_Input_Data()
        {
            ServiceJSON service = new ServiceJSON();

            Customer customer = new Customer {
                FirstName = "Steve",
                LastName  = "Jobs"
            };

            Account account = new Account {
                UserName = "******",
                Password = "******"
            };
            ServiceJSONInput inputData = new ServiceJSONInput {
                Customer = customer,
                Account  = account
            };

            ServiceJSONResult response = service.MyMethod(inputData);

            Assert.True(response.Exception == null);
            Assert.True(response.Customer == customer);
            Assert.True(response.Message != null);
        }
Пример #4
0
 public IAsyncResult BeginMyMethod(ServiceJSONInput input, AsyncCallback callback, object asyncState)
 {
     return(new CompletedAsyncResult <ServiceJSONResult>((MyMethod(input))));
 }