static void Main(string[] args) { ISimpleService srvc = new SimpleServiceClient(); Console.WriteLine(srvc.GetData()); Console.ReadLine(); }
static void Main(string[] args) { var soapClient = new SimpleServiceClient(); var soapResponse = soapClient.GetData(4234); if (soapResponse != null) { Console.WriteLine(soapResponse); } var request = new AuthenticationRequest { Username = "******", Password = "******" }; var soapResponse2 = soapClient.Authenticate(request); soapClient.Close(); using (var restClient = new HttpClient { BaseAddress = new Uri("http://localhost:63852/SimpleService.svc/json/") }) { var serilized = JsonConvert.SerializeObject(request); var inputMessage = new HttpRequestMessage { Content = new StringContent(serilized, Encoding.UTF8, "application/json") }; inputMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var message = restClient.PutAsync("AuthReq", inputMessage.Content).Result; AuthorizationResponse restResponse = null; if (message.IsSuccessStatusCode) { var inter = message.Content.ReadAsStringAsync(); restResponse = JsonConvert.DeserializeObject <AuthorizationResponse>(inter.Result); } if (restResponse != null) { Console.WriteLine(restResponse.Message); } } Console.ReadKey(); }
static void Main(string[] args) { // Vytvorenie instancie proxy triedy, pomocou ktorej mozeme volat vzdialene metody var client = new SimpleServiceClient(); // Zavolame vzdialenu metodu GetData - sluzba vrati retazec var resultString = client.GetData(123); Console.WriteLine(resultString); var compositeType = new CompositeType { StringValue = "Volam WCF sluzbu", BoolValue = true }; var resultCompositeType = client.GetDataUsingDataContract(compositeType); Console.WriteLine(resultCompositeType.StringValue); Console.ReadLine(); client.Close(); }
public static void Main(string[] args) { var simpleServiceClient = new SimpleServiceClient(); var simpleServiceCustomClient = new SimpleServiceCustomProxy(new BasicHttpBinding(), new System.ServiceModel.EndpointAddress(@"http://localhost:8123/SimpleService/")); var dulplexServiceClient = new DulplexServiceClient(new System.ServiceModel.InstanceContext(new DulplexServiceCallback())); var dulplexServiceClient2 = new DulplexServiceClient(new System.ServiceModel.InstanceContext(new DulplexServiceCallback())); try { Console.WriteLine("Client - Start."); Console.WriteLine(simpleServiceClient.GetData(5)); Console.WriteLine(simpleServiceCustomClient.GetData(2)); var obj = new Contracts.CompositeType(); obj.BoolValue = true; obj.StringValue = "hello"; var obj1 = simpleServiceCustomClient.GetDataUsingDataContract(obj); var obj2 = simpleServiceClient.GetDataUsingDataContract(obj); simpleServiceClient.Close(); dulplexServiceClient.Subscribe(); dulplexServiceClient2.Subscribe(); dulplexServiceClient2.Subscribe(); dulplexServiceClient2.UnSubscribe(); dulplexServiceClient2.UnSubscribe(); dulplexServiceClient2.UnSubscribe(); dulplexServiceClient2.Close(); dulplexServiceClient.Add(7, 8); //dulplexServiceClient.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); simpleServiceClient.Abort(); dulplexServiceClient.Abort(); } Console.Read(); }