public void GivenISubscribe() { client = new SampleServiceClient(); var response = client.DoSampleRequest("Sample Request"); ScenarioContext.Current.Set(response); }
/// <summary> /// Function that governs behavior after filter button has been clicked. /// </summary> /// <param name="sender"> /// The object that handles the behavior. /// </param> /// <param name="e"> /// The event trigger. /// </param> protected void FilterGridViewClick(object sender, EventArgs e) { var filteredAppointments = new SampleServiceClient().GetFilteredAppointments( this.SearchCriteria.SelectedValue, this.SearchByTagTextBox.Text); var dataTable = new DataTable(); dataTable.Columns.AddRange(new[] { new DataColumn("AppointmentID", typeof(string)), new DataColumn("IsActive", typeof(string)), new DataColumn("PatientID", typeof(string)), new DataColumn("StartDateTime", typeof(string)), new DataColumn("DurationID", typeof(string)), new DataColumn("ClinicID", typeof(string)), new DataColumn("SpecialtyID", typeof(string)) }); foreach (var appointment in filteredAppointments) { dataTable.Rows.Add( appointment.AppointmentId, appointment.IsActive ? "Active" : "Cancelled", string.Join(" ", appointment.Patient.FirstName, appointment.Patient.Surname), appointment.StartDateTime, appointment.Duration.AppointmentLength, appointment.Clinic.CodeDescription, appointment.Specialty.CodeDescription); } this.SearchResultsGrid.DataSource = dataTable; this.SearchResultsGrid.DataBind(); }
public SampleServiceClient() : base(SampleServiceClient.GetDefaultBinding(), SampleServiceClient.GetDefaultEndpointAddress()) { this.Endpoint.Name = EndpointConfiguration.BasicHttpBinding.ToString(); ConfigureEndpoint(this.Endpoint, this.ClientCredentials); }
public static void Main() { // Picks up configuration from the config file. SampleServiceClient wcfClient = new SampleServiceClient(); try { // Making calls. Console.WriteLine("Enter the greeting to send: "); string greeting = Console.ReadLine(); Console.WriteLine("The service responded: " + wcfClient.SampleMethod(greeting)); Console.WriteLine("Press ENTER to exit:"); Console.ReadLine(); // Done with service. wcfClient.Close(); Console.WriteLine("Done!"); } catch (TimeoutException timeProblem) { Console.WriteLine("The service operation timed out. " + timeProblem.Message); wcfClient.Abort(); Console.Read(); } catch (CommunicationException commProblem) { Console.WriteLine("There was a communication problem. " + commProblem.Message); wcfClient.Abort(); Console.Read(); } }
private void ProcessResponse(IAsyncResult result) { try { Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("In the async response handler."); SampleServiceClient responseClient = (SampleServiceClient)(result.AsyncState); string response = responseClient.EndSampleMethod(result); Console.Write("ProcessResponse: "); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(response); Console.ResetColor(); } catch (TimeoutException timeProblem) { Console.WriteLine("The service operation timed out. " + timeProblem.Message); } catch (CommunicationException commProblem) { Console.WriteLine("There was a communication problem. " + commProblem.Message); } catch (Exception e) { Console.WriteLine("There was an exception: " + e.Message); } }
/// <summary> /// Function that builds the data table that stores all appointments stored in database ready for display on frontend. /// </summary> public void MakeCurrentAppointmentsTable() { var appointmentDataTable = new DataTable(); var appointments = new SampleServiceClient().GetAppointments(); appointmentDataTable.Columns.AddRange(new[] { new DataColumn("AppointmentID", typeof(string)), new DataColumn("IsActive", typeof(string)), new DataColumn("PatientID", typeof(string)), new DataColumn("StartDateTime", typeof(string)), new DataColumn("DurationID", typeof(string)), new DataColumn("ClinicID", typeof(string)), new DataColumn("SpecialtyID", typeof(string)) }); foreach (var appointment in appointments) { appointmentDataTable.Rows.Add( appointment.AppointmentId, appointment.IsActive ? "Active" : "Cancelled", string.Join(" ", appointment.Patient.FirstName, appointment.Patient.Surname), appointment.StartDateTime, appointment.Duration.AppointmentLength, appointment.Clinic.CodeDescription, appointment.Specialty.CodeDescription); } this.Session["appointmentDataTable"] = appointmentDataTable; this.SearchResultsGrid.DataSource = appointmentDataTable; this.SearchResultsGrid.DataBind(); }
static void Main(string[] args) { SampleServiceClient client = new SampleServiceClient(); JObject j1 = client.SayHello("HXF"); Console.WriteLine(j1["Value"]); JObject j2 = client.Sum(5, 3); Console.WriteLine(j2["Value"]); }
static void Main(string[] args) { using (SampleServiceClient client = new SampleServiceClient()) { var retorno = client.SampleMethod("Ricardo"); Console.WriteLine(retorno); // Hell World }; Console.ReadKey(); }
void Run() { // Picks up configuration from the config file. using (SampleServiceClient wcfClient = new SampleServiceClient()) { try { // Make asynchronous call. Console.WriteLine("Enter the greeting to send asynchronously: "); string greeting = Console.ReadLine(); IAsyncResult waitResult = wcfClient.BeginSampleMethod(greeting, new AsyncCallback(ProcessResponse), wcfClient); Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Sent asynchronous method. Waiting on the response."); waitResult.AsyncWaitHandle.WaitOne(); Console.ResetColor(); // Make synchronous call. Console.WriteLine("Enter the greeting to send synchronously: "); greeting = Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Blue; Console.Write("Response: "); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(wcfClient.SampleMethod(greeting)); Console.ResetColor(); // Make synchronous call on asynchronous method. Console.WriteLine("Enter the greeting to send synchronously to async service operation: "); greeting = Console.ReadLine(); Console.ForegroundColor = ConsoleColor.Blue; Console.Write("Response: "); Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(wcfClient.ServiceAsyncMethod(greeting)); Console.ResetColor(); Console.WriteLine("Press ENTER to exit:"); Console.ReadLine(); // Done with service. wcfClient.Close(); Console.WriteLine("Done!"); } catch (TimeoutException timeProblem) { Console.WriteLine("The service operation timed out. " + timeProblem.Message); Console.Read(); wcfClient.Abort(); } catch (CommunicationException commProblem) { Console.WriteLine("There was a communication problem. " + commProblem.Message); Console.Read(); wcfClient.Abort(); } } }
public static void Main() { // Picks up configuration from the config file. SampleServiceClient wcfClient = new SampleServiceClient(); try { // Making calls. Console.WriteLine("Enter the greeting to send: "); string greeting = Console.ReadLine(); wcfClient.Open(); Console.WriteLine("The service responded: " + wcfClient.SampleMethod(greeting)); Console.WriteLine("The service responded: " + wcfClient.SampleMethod(greeting)); Console.WriteLine("The service responded: " + wcfClient.SampleMethod(greeting)); // Done with service. wcfClient.Close(); Console.WriteLine("Done!"); SampleServiceClient newclient = new SampleServiceClient(); newclient.Open(); Console.WriteLine("The service responded: " + newclient.SampleMethod(greeting)); Console.WriteLine("The service responded: " + newclient.SampleMethod(greeting)); Console.WriteLine("Press ENTER to exit:"); Console.ReadLine(); // Done with service. newclient.Close(); ChannelFactory <ISampleServiceChannel> chFactory = new ChannelFactory <ISampleServiceChannel>("WSHttpBinding_ISampleService"); ISampleServiceChannel clientChannel = chFactory.CreateChannel(); clientChannel.Open(); Console.Read(); clientChannel.SampleMethod(greeting); clientChannel.SampleMethod(greeting); clientChannel.SampleMethod(greeting); clientChannel.Close(); Console.WriteLine("Done!"); } catch (TimeoutException timeProblem) { Console.WriteLine("The service operation timed out. " + timeProblem.Message); Console.Read(); } catch (FaultException <SampleFault> fault) { Console.WriteLine("SampleFault fault occurred: {0}", fault.Detail.FaultMessage); Console.Read(); } catch (CommunicationException commProblem) { Console.WriteLine("There was a communication problem. " + commProblem.Message); Console.Read(); } }
void Run() { // Picks up configuration from the config file. // <snippet4> SampleServiceClient wcfClient = new SampleServiceClient(new InstanceContext(this)); try { using (OperationContextScope scope = new OperationContextScope(wcfClient.InnerChannel)) { MessageHeader header = MessageHeader.CreateHeader( "Service-Bound-CustomHeader", "http://Microsoft.WCF.Documentation", "Custom Happy Value." ); OperationContext.Current.OutgoingMessageHeaders.Add(header); // Making calls. Console.WriteLine("Enter the greeting to send: "); string greeting = Console.ReadLine(); //Console.ReadLine(); header = MessageHeader.CreateHeader( "Service-Bound-OneWayHeader", "http://Microsoft.WCF.Documentation", "Different Happy Value." ); OperationContext.Current.OutgoingMessageHeaders.Add(header); // One-way wcfClient.Push(greeting); this.wait.WaitOne(); // Done with service. wcfClient.Close(); Console.WriteLine("Done!"); Console.ReadLine(); } } catch (TimeoutException timeProblem) { Console.WriteLine("The service operation timed out. " + timeProblem.Message); Console.ReadLine(); wcfClient.Abort(); } catch (CommunicationException commProblem) { Console.WriteLine("There was a communication problem. " + commProblem.Message); Console.ReadLine(); wcfClient.Abort(); } // </snippet4> }
public PreConfiguredServerTests() { var testRunValues = new TestRunValues(); _server = new Server { Services = { BindService(new DumbPipeServiceImplementation(new EchoValueService())) }, Ports = { new ServerPort(testRunValues.Host, testRunValues.Port, testRunValues.ServerCredentials) } }; _channel = new Channel(testRunValues.HostAddress, testRunValues.ClientCredentials); _client = new SampleServiceClient(_channel); }
/// <summary> /// Creates data table for list of specialties linked to clinics. /// </summary> public void MakeClinicSpecialtyTable() { var dataTable = new DataTable(); dataTable.Columns.Add("ClinicSpecialtyID"); dataTable.Columns.Add("Clinic"); dataTable.Columns.Add("Specialty"); var clinicSpecialtyList = new SampleServiceClient().GetClinicSpecialties(); foreach (var clinicSpecialty in clinicSpecialtyList) { dataTable.Rows.Add(clinicSpecialty.ClinicSpecialtyId, clinicSpecialty.Clinic, clinicSpecialty.Specialty); } }
public async Task <ActionResult> RequestReplyOperation_ThrowsExceptionAsync() { string message = string.Empty; try { SampleServiceClient client = new SampleServiceClient(); await client.RequestReplyOperation_ThrowsExceptionAsync(); } catch (Exception ex) { message = $"Request-Reply Throws Exception Operation Completed @ {DateTime.Now} {ex.Message}"; } return(PartialView("RequestReplyOperation_ThrowsException", message)); }
public static void Main() { // Picks up configuration from the configuration file. SampleServiceClient wcfClient = new SampleServiceClient(); try { // Making calls. Console.WriteLine("Enter the greeting to send: "); string greeting = Console.ReadLine(); Console.WriteLine("The service responded: " + wcfClient.SampleMethod(greeting)); Console.WriteLine("Press ENTER to exit:"); Console.ReadLine(); } catch (TimeoutException timeProblem) { Console.WriteLine("The service operation timed out. " + timeProblem.Message); wcfClient.Abort(); Console.ReadLine(); } // Catch the contractually specified SOAP fault raised here as an exception. catch (FaultException <GreetingFault> greetingFault) { Console.WriteLine(greetingFault.Detail.Message); Console.Read(); wcfClient.Abort(); } // Catch unrecognized faults. This handler receives exceptions thrown by WCF // services when ServiceDebugBehavior.IncludeExceptionDetailInFaults // is set to true. catch (FaultException faultEx) { Console.WriteLine("An unknown exception was received. " + faultEx.Message + faultEx.StackTrace ); Console.Read(); wcfClient.Abort(); } // Standard communication fault handler. catch (CommunicationException commProblem) { Console.WriteLine("There was a communication problem. " + commProblem.Message + commProblem.StackTrace); Console.Read(); wcfClient.Abort(); } }
static void Main(string[] args) { SampleServiceClient client = new SampleServiceClient(); try { for (int i = 0; i < 10; i++) { // This will post (In the service): // "Hey! Test #x" until an exception happens or it goes 10 times without an exception. string test = client.SampleMethod("Test #" + i); Console.WriteLine(test); } } catch (TimeoutException timeProblem) { Console.WriteLine("The service operation timed out. " + timeProblem.Message); Console.ReadLine(); client.Abort(); } catch (FaultException<GreetingFault> greetingFault) { Console.WriteLine(greetingFault.Detail.Message); Console.ReadLine(); client.Abort(); } catch (FaultException unknownFault) { Console.WriteLine("An unknown exception was received. " + unknownFault.Message); Console.ReadLine(); client.Abort(); } catch (CommunicationException commProblem) { Console.WriteLine("There was a communication problem. " + commProblem.Message + commProblem.StackTrace); Console.ReadLine(); client.Abort(); } finally { client.Close(); } }
/// <summary> /// Creates data table for all clinics stored on database. /// </summary> public void MakeClinicTable() { var dataTable = new DataTable(); dataTable.Columns.Add("ClinicID"); dataTable.Columns.Add("CodeDescription"); var clinicList = new SampleServiceClient().GetClinics(); foreach (var clinic in clinicList) { dataTable.Rows.Add(clinic.ClinicId, clinic.CodeDescription); } this.ClinicDropDownList.DataSource = dataTable; this.ClinicDropDownList.DataTextField = "CodeDescription"; this.ClinicDropDownList.DataValueField = "ClinicID"; this.ClinicDropDownList.DataBind(); }
/// <summary> /// Actions taken when index of clinic drop down is changed. /// This will change values stored in specialty drop down, /// simulating our clinic specialties. /// </summary> /// <param name="sender"> /// The object that performs the required actions. /// </param> /// <param name="e"> /// The event that acts as a trigger. /// </param> protected void ClinicDropDownListSelectedIndexChanged(object sender, EventArgs e) { var dataTable = new DataTable(); dataTable.Columns.Add("ClinicSpecialtyID"); dataTable.Columns.Add("CodeDescription"); var clinicSpecialtyList = new SampleServiceClient().GetFilteredClinicSpecialties(this.ClinicDropDownList.SelectedValue); foreach (var clinicSpecialty in clinicSpecialtyList) { dataTable.Rows.Add(clinicSpecialty.Specialty.SpecialtyId, clinicSpecialty.Specialty.CodeDescription); } this.SpecialtyDropDownList.DataSource = dataTable; this.SpecialtyDropDownList.DataTextField = "CodeDescription"; this.SpecialtyDropDownList.DataValueField = "ClinicSpecialtyID"; this.SpecialtyDropDownList.DataBind(); }
/// <summary> /// A function that creates a data table for all patients. This is displayed in a drop down. /// </summary> public void MakePatientTable() { var dataTable = new DataTable(); dataTable.Columns.Add("PatientNo"); dataTable.Columns.Add("Patient Name"); var patientList = new SampleServiceClient().GetPatients(); foreach (var patient in patientList) { dataTable.Rows.Add(patient.PatientId, string.Join(" ", patient.FirstName, patient.Surname)); } this.PatientDropDownList.DataSource = dataTable; this.PatientDropDownList.DataTextField = "Patient Name"; this.PatientDropDownList.DataValueField = "PatientNo"; this.PatientDropDownList.DataBind(); }
public ActionResult RequestReplyOperation() { string message; try { SampleServiceClient client = new SampleServiceClient(); string processingTime = client.RequestReplyOperation(); message = $"Request-Reply Operation Completed @ {DateTime.Now} - {processingTime}"; } catch (Exception ex) { message = ex.Message; } return(PartialView("RequestReplyOperation", message)); }
/// <summary> /// Creates data table for all appointment types stored on database. /// </summary> public void MakeAppointmentTypeTable() { var dataTable = new DataTable(); dataTable.Columns.Add("AppointmentTypeID"); dataTable.Columns.Add("TypeDescriptor"); var appointmentTypeList = new SampleServiceClient().GetAppointmentTypes(); foreach (var type in appointmentTypeList) { dataTable.Rows.Add(type.AppointmentTypeId, type.TypeDescriptor); } this.AppointmentTypeDropDownList.DataSource = dataTable; this.AppointmentTypeDropDownList.DataTextField = "TypeDescriptor"; this.AppointmentTypeDropDownList.DataValueField = "AppointmentTypeID"; this.AppointmentTypeDropDownList.DataBind(); }
/// <summary> /// Creates data table for all appointment urgencies stored on database. /// </summary> public void MakeUrgencyTable() { var dataTable = new DataTable(); dataTable.Columns.Add("UrgencyID"); dataTable.Columns.Add("UrgencyDescriptor"); var urgencyList = new SampleServiceClient().GetUrgencies(); foreach (var urgency in urgencyList) { dataTable.Rows.Add(urgency.UrgencyId, urgency.UrgencyDescriptor); } this.UrgencyDropDownList.DataSource = dataTable; this.UrgencyDropDownList.DataTextField = "UrgencyDescriptor"; this.UrgencyDropDownList.DataValueField = "UrgencyID"; this.UrgencyDropDownList.DataBind(); }
/// <summary> /// Creates data table for all appointment durations stored on database. /// </summary> public void MakeDurationTable() { var dataTable = new DataTable(); dataTable.Columns.Add("DurationID"); dataTable.Columns.Add("AppointmentLength"); var durationList = new SampleServiceClient().GetAllAppointmentDurationData(); foreach (var duration in durationList) { dataTable.Rows.Add(duration.DurationId, duration.AppointmentLength); } this.DurationDropDownList.DataSource = dataTable; this.DurationDropDownList.DataTextField = "AppointmentLength"; this.DurationDropDownList.DataValueField = "DurationID"; this.DurationDropDownList.DataBind(); }
public string Ask(string question) { SampleServiceClient proxy = null; string response = null; int callCount = 0; bool callCompleted = false; bool shouldRetry = true; while (!callCompleted && callCount < MaxRetryCount && shouldRetry) { callCount++; try { proxy = new SampleServiceClient(); var svcResponse = proxy.AskQuestion(new SampleServiceRequest { Question = "Are we nearly there yet?" }); if (svcResponse != null) response = svcResponse.Answer; callCompleted = true; } catch (EndpointNotFoundException ex) { if (callCount >= MaxRetryCount && !callCompleted) { throw; } else { Console.WriteLine("Can't find service - going to sit here patiently for 2seconds before trying again."); Thread.Sleep(2000); // Do nothing } } catch (Exception ex) { shouldRetry = false; } finally { if (proxy != null) { try { if (proxy.State == CommunicationState.Opened) proxy.Close(); else if (proxy.State == CommunicationState.Faulted) proxy.Abort(); } catch (CommunicationException) { proxy.Abort(); } catch (TimeoutException) { proxy.Abort(); } } } } return response; }
static async System.Threading.Tasks.Task Main(string[] args) { SampleServiceClient client = new SampleServiceClient(); using (new OperationContextScope(client.InnerChannel)) { // We will use a custom class called UserInfo to be passed in as a MessageHeader string bearerToken = "Bearer 23y7289387893728938792309023092"; // Add a SOAP Header to an outgoing request MessageHeader aMessageHeader = MessageHeader.CreateHeader("Authorization", "http://tempuri.org", bearerToken); OperationContext.Current.OutgoingMessageHeaders.Add(aMessageHeader); // Add a HTTP Header to an outgoing request HttpRequestMessageProperty requestMessage = new HttpRequestMessageProperty(); requestMessage.Headers["Authorization"] = "Bearer 23y7289387893728938792309023092"; OperationContext.Current.OutgoingMessageProperties[HttpRequestMessageProperty.Name] = requestMessage; var result = await client.PingAsync("Hello"); } }
/// <summary> /// Wrapper around our service call to ensure it is being correctly disposed /// </summary> /// <typeparam name="TResult"></typeparam> /// <param name="serviceCall"></param> /// <returns></returns> private TResult MakeSampleServiceCall <TResult>(Func <SampleService.SampleServiceClient, TResult> serviceCall) { SampleServiceClient client = null; try { client = new SampleServiceClient(); var result = serviceCall(client); client.Close(); return(result); } catch { if (client != null) { client.Abort(); } throw; } }
public static void Main() { // Picks up configuration from the config file. SampleServiceClient wcfClient = new SampleServiceClient(); try { // Add the client side behavior programmatically. wcfClient.Endpoint.Behaviors.Add(new EndpointBehaviorMessageInspector()); // Making calls. Console.WriteLine("Enter the greeting to send: "); string greeting = Console.ReadLine(); Console.WriteLine("The service responded: " + wcfClient.SampleMethod(greeting)); Console.WriteLine("Press ENTER to exit:"); Console.ReadLine(); // Done with service. wcfClient.Close(); Console.WriteLine("Done!"); } catch (TimeoutException timeProblem) { Console.WriteLine("The service operation timed out. " + timeProblem.Message); Console.Read(); } catch (FaultException <SampleFault> fault) { Console.WriteLine("SampleFault fault occurred: {0}", fault.Detail.FaultMessage); Console.Read(); } catch (CommunicationException commProblem) { Console.WriteLine("There was a communication problem. " + commProblem.Message); Console.Read(); } }
static void Main() { // Get a client for the service SampleServiceClient wcfClient = new SampleServiceClient(); // Call the GetData method on the server string retstr = wcfClient.GetData(123); Console.WriteLine("GetData returns: " + retstr); // Create the CompositeType object from the service and execute // the GetDataUsingDataContract method on the server CompositeType obj = new CompositeType(); obj.BoolValue = true; obj.StringValue = "Hello WCF client"; CompositeType objret = wcfClient.GetDataUsingDataContract(obj); Console.WriteLine("GetDataUsingDataContract returns: " + objret.StringValue); Console.ReadLine(); // Close the connection to the server wcfClient.Close(); }
public AddSimpleServiceImplementationTests() { _testRunValues = new TestRunValues(); _channel = new Channel(_testRunValues.HostAddress, _testRunValues.ClientCredentials); _client = new SampleServiceClient(_channel); }
private static System.ServiceModel.EndpointAddress GetDefaultEndpointAddress() { return(SampleServiceClient.GetEndpointAddress(EndpointConfiguration.BasicHttpBinding)); }
private static System.ServiceModel.Channels.Binding GetDefaultBinding() { return(SampleServiceClient.GetBindingForEndpoint(EndpointConfiguration.BasicHttpBinding)); }
public SampleServiceClient(EndpointConfiguration endpointConfiguration, System.ServiceModel.EndpointAddress remoteAddress) : base(SampleServiceClient.GetBindingForEndpoint(endpointConfiguration), remoteAddress) { this.Endpoint.Name = endpointConfiguration.ToString(); ConfigureEndpoint(this.Endpoint, this.ClientCredentials); }
public SampleServiceClient(EndpointConfiguration endpointConfiguration) : base(SampleServiceClient.GetBindingForEndpoint(endpointConfiguration), SampleServiceClient.GetEndpointAddress(endpointConfiguration)) { this.Endpoint.Name = endpointConfiguration.ToString(); ConfigureEndpoint(this.Endpoint, this.ClientCredentials); }