public GreetingResponse Hello(Greeting greeting) { GreetingResponse response = new GreetingResponse(); response.Text = "Hello Client!"; return response; }
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(); }