static void Main(string[] args) { var binding = new BasicHttpBinding(); var endpoint = new EndpointAddress("http://localhost:8000/SEP"); try { var client = new HelloServiceClient(binding, endpoint); while (true) { Console.Clear(); ShowHelp(); var name = Console.ReadLine(); if (string.IsNullOrEmpty(name)) { break; } var ret = client.SayHello(name); Console.WriteLine(ret); Console.WriteLine("Hit <ENTER> to continue"); Console.ReadLine(); } Console.ReadLine(); client.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
static void Main(string[] args) { HelloServiceClient wcfClient = new HelloServiceClient(); CompositeType obj = new CompositeType(); obj.BoolValue = true; obj.StringValue = "Hello WCF TCP client!"; CompositeType objret = wcfClient.GetDataUsingDataContract(obj); Console.WriteLine("GetDataUsingDataContract returns: " + objret.StringValue); Console.ReadLine(); wcfClient.Close(); }
static void Main() { Console.WriteLine("*** Call 'Hello' with svcutil-generated client"); HelloServiceClient helloClient = new HelloServiceClient(); Greeting greeting = new Greeting(); greeting.text = "Hello Server!"; GreetingResponse response = helloClient.Hello(greeting); Console.WriteLine(response.text); helloClient.Close(); try { Console.WriteLine("*** Call 'Hello' with generic client, no client behavior"); GenericClient client = new GenericClient(); Console.WriteLine("--- Sending valid client request:"); GenericCallValid(client, helloAction); Console.WriteLine("--- Sending invalid client request:"); GenericCallInvalid(client, helloAction); client.Close(); } catch (Exception e) { DumpException(e); } try { Console.WriteLine("*** Call 'Hello' with generic client, with client behavior"); GenericClient client = new GenericClient(); // Configure client programmatically, adding behavior XmlSchema schema = XmlSchema.Read(new StreamReader("messages.xsd"), null); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add(schema); client.Endpoint.Behaviors.Add(new SchemaValidationBehavior(schemaSet, true, true)); Console.WriteLine("--- Sending valid client request:"); GenericCallValid(client, helloAction); Console.WriteLine("--- Sending invalid client request:"); GenericCallInvalid(client, helloAction); client.Close(); } catch (Exception e) { DumpException(e); } Console.WriteLine("*** Call 'HelloToo' with generic client, no client behavior"); try { GenericClient client = new GenericClient(); Console.WriteLine("--- Sending valid client request, malformed service reply:"); GenericCallValid(client, helloTooAction); client.Close(); } catch (Exception e) { DumpException(e); } Console.WriteLine("*** Call 'HelloToo' with generic client, with client behavior, no service behavior"); try { GenericClient client = new GenericClient(); XmlSchema schema = XmlSchema.Read(new StreamReader("messages.xsd"), null); XmlSchemaSet schemaSet = new XmlSchemaSet(); schemaSet.Add(schema); client.Endpoint.Address = new EndpointAddress(client.Endpoint.Address.Uri.ToString() + "/novalidation"); client.Endpoint.Behaviors.Add(new SchemaValidationBehavior(schemaSet, true, true)); Console.WriteLine("--- Sending valid client request, malformed service reply:"); GenericCallValid(client, helloTooAction); client.Close(); } catch (Exception e) { DumpException(e); } Console.WriteLine(); Console.WriteLine("Press <ENTER> to terminate client."); Console.ReadLine(); }