private void btnHello_Click(object sender, EventArgs e) { try { if (client.State == System.ServiceModel.CommunicationState.Faulted) { client = new HelloServiceClient(); } lblMessage.Text = client.Hello(txtName.Text); } catch (Exception ex) { lblMessage.Text = ex.Message; } }
private void btnHello_Click(object sender, EventArgs e) { HelloServiceClient client = new HelloServiceClient(); lblMessage.Text = client.Hello(txtName.Text); }
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(); }
private void btnHello_Click(object sender, EventArgs e) { lblMessage.Text = client.Hello(txtName.Text); }