public static void Main(string[] args) { var binding = new BasicHttpBinding(); var endpoint = new EndpointAddress(new Uri(string.Format("http://{0}:5050/Service.svc", Environment.MachineName))); var channelFactory = new ChannelFactory <ISampleService>(binding, endpoint); var serviceClient = channelFactory.CreateChannel(); var result = serviceClient.Ping("hey"); Console.WriteLine("Ping method result: {0}", result); var complexModel = new ComplexModelInput { StringProperty = Guid.NewGuid().ToString(), IntProperty = int.MaxValue / 2, ListProperty = new List <string> { "test", "list", "of", "strings" }, DateTimeOffsetProperty = new DateTimeOffset(2018, 12, 31, 13, 59, 59, TimeSpan.FromHours(1)) }; var complexResult = serviceClient.PingComplexModel(complexModel); Console.WriteLine("PingComplexModel result. FloatProperty: {0}, StringProperty: {1}, ListProperty: {2}, DateTimeOffsetProperty: {3}", complexResult.FloatProperty, complexResult.StringProperty, string.Join(", ", complexResult.ListProperty), complexResult.DateTimeOffsetProperty); serviceClient.VoidMethod(out var stringValue); Console.WriteLine("Void method result: {0}", stringValue); var asyncMethodResult = serviceClient.AsyncMethod().Result; Console.WriteLine("Async method result: {0}", asyncMethodResult); Console.ReadKey(); }
public static void Main(string[] args) { var binding = new BasicHttpBinding(); var endpoint = new EndpointAddress(new Uri(string.Format("http://{0}:5050/Service.svc", Environment.MachineName))); var channelFactory = new ChannelFactory <ISampleService>(binding, endpoint); var serviceClient = channelFactory.CreateChannel(); var result = serviceClient.Ping("hey"); Console.WriteLine("Ping method result: {0}", result); var complexModel = new ComplexModelInput { StringProperty = Guid.NewGuid().ToString(), IntProperty = int.MaxValue / 2 }; var complexResult = serviceClient.PingComplexModel(complexModel); Console.WriteLine("PingComplexModel result. FloatProperty: {0}, StringProperty: {1}", complexResult.FloatProperty, complexResult.StringProperty); serviceClient.VoidMethod(out var stringValue); Console.WriteLine("Void method result: {0}", stringValue); var asyncMethodResult = serviceClient.AsyncMethod().Result; Console.WriteLine("Async method result: {0}", asyncMethodResult); Console.ReadKey(); }
private bool PingComplexModelOutAndRefImplementation( ComplexModelInput inputModel, ref ComplexModelResponse responseModelRef1, ComplexObject data1, ref ComplexModelResponse responseModelRef2, ComplexObject data2, out ComplexModelResponse responseModelOut1, out ComplexModelResponse responseModelOut2) { Console.WriteLine("input params:\n"); Console.WriteLine($"{nameof(inputModel)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(inputModel)}\n"); Console.WriteLine($"{nameof(responseModelRef1)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(responseModelRef1)}\n"); Console.WriteLine($"{nameof(responseModelRef2)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(responseModelRef2)}\n"); Console.WriteLine($"{nameof(data1)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(data1)}\n"); Console.WriteLine($"{nameof(data2)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(data2)}\n"); responseModelRef1 = ComplexModelResponse.CreateSample2(); responseModelRef2 = ComplexModelResponse.CreateSample1(); responseModelOut1 = ComplexModelResponse.CreateSample3(); responseModelOut2 = ComplexModelResponse.CreateSample1(); Console.WriteLine("output params:\n"); Console.WriteLine($"{nameof(responseModelRef1)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(responseModelRef1)}\n"); Console.WriteLine($"{nameof(responseModelRef2)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(responseModelRef2)}\n"); Console.WriteLine($"{nameof(responseModelOut1)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(responseModelOut1)}\n"); Console.WriteLine($"{nameof(responseModelOut2)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(responseModelOut2)}\n"); Console.WriteLine("done.\n"); return(true); }
public ComplexModelResponse PingComplexModel(ComplexModelInput inputModel) { Console.WriteLine("Input data. IntProperty: {0}, StringProperty: {1}", inputModel.IntProperty, inputModel.StringProperty); return(new ComplexModelResponse { FloatProperty = float.MaxValue / 2, StringProperty = Guid.NewGuid().ToString() }); }
public void TestPingComplexModelOutAndRefSerialization() { this.fixture.sampleServiceMock .Setup(x => x.PingComplexModelOutAndRef( It.IsAny <ComplexModelInput>(), ref It.Ref <ComplexModelResponse> .IsAny, It.IsAny <ComplexObject>(), ref It.Ref <ComplexModelResponse> .IsAny, It.IsAny <ComplexObject>(), out It.Ref <ComplexModelResponse> .IsAny, out It.Ref <ComplexModelResponse> .IsAny)) .Callback(new PingComplexModelOutAndRefCallback( (ComplexModelInput inputModel_service, ref ComplexModelResponse responseModelRef1_service, ComplexObject data1_service, ref ComplexModelResponse responseModelRef2_service, ComplexObject data2_service, out ComplexModelResponse responseModelOut1_service, out ComplexModelResponse responseModelOut2_service) => { // check input paremeters serialization inputModel_service.ShouldDeepEqual(ComplexModelInput.CreateSample1()); responseModelRef1_service.ShouldDeepEqual(ComplexModelResponse.CreateSample1()); responseModelRef2_service.ShouldDeepEqual(ComplexModelResponse.CreateSample2()); data1_service.ShouldDeepEqual(ComplexObject.CreateSample1()); data2_service.ShouldDeepEqual(ComplexObject.CreateSample2()); // sample response responseModelRef1_service = ComplexModelResponse.CreateSample2(); responseModelRef2_service = ComplexModelResponse.CreateSample1(); responseModelOut1_service = ComplexModelResponse.CreateSample3(); responseModelOut2_service = ComplexModelResponse.CreateSample1(); })) .Returns(true); var responseModelRef1_client = ComplexModelResponse.CreateSample1(); var responseModelRef2_client = ComplexModelResponse.CreateSample2(); var pingComplexModelOutAndRefResult_client = this.fixture.sampleServiceClient.PingComplexModelOutAndRef( ComplexModelInput.CreateSample1(), ref responseModelRef1_client, ComplexObject.CreateSample1(), ref responseModelRef2_client, ComplexObject.CreateSample2(), out var responseModelOut1_client, out var responseModelOut2_client); // check output paremeters serialization pingComplexModelOutAndRefResult_client.ShouldBeTrue(); responseModelRef1_client.ShouldDeepEqual(ComplexModelResponse.CreateSample2()); responseModelRef2_client.ShouldDeepEqual(ComplexModelResponse.CreateSample1()); responseModelOut1_client.ShouldDeepEqual(ComplexModelResponse.CreateSample3()); responseModelOut2_client.ShouldDeepEqual(ComplexModelResponse.CreateSample1()); }
public ComplexModelResponse PingComplexModel(ComplexModelInput inputModel) { Console.WriteLine("Input data. IntProperty: {0}, StringProperty: {1}", inputModel.IntProperty, inputModel.StringProperty); return(new ComplexModelResponse { FloatProperty = float.MaxValue / 2, StringProperty = inputModel.StringProperty, ListProperty = inputModel.ListProperty, DateTimeOffsetProperty = inputModel.DateTimeOffsetProperty }); }
public void ModelWasNotAlteredInModelBindingFilter() { var inputModel = new ComplexModelInput { StringProperty = "string property test value", IntProperty = 123, ListProperty = new List <string> { "test", "list", "of", "strings" }, DateTimeOffsetProperty = new DateTimeOffset(2018, 12, 31, 13, 59, 59, TimeSpan.FromHours(1)) }; var client = CreateClient(); var result = client.ComplexParam(inputModel); Assert.AreEqual(inputModel.StringProperty, result.StringProperty); Assert.AreEqual(inputModel.IntProperty, result.IntProperty); }
public async Task <string> Get() { var complexModel = new ComplexModelInput { StringProperty = Guid.NewGuid().ToString(), IntProperty = new Random().Next(), ListProperty = new[] { "test", "list", "of", "strings" }, DateTimeOffsetProperty = RandomDay() }; var complexResult = await sampleService.PingComplexModelAsync(complexModel); return($"result. FloatProperty: {complexResult.FloatProperty}, " + $"StringProperty: {complexResult.StringProperty}, " + $"ListProperty: {string.Join(" ", complexResult.ListProperty)}, " + $"DateTimeOffsetProperty: {complexResult.DateTimeOffsetProperty}, " + $"EnumProperty: {complexResult.TestEnum}"); }
public bool PingComplexModelOutAndRef( ComplexModelInput inputModel, ref ComplexModelResponse responseModelRef1, ComplexObject data1, ref ComplexModelResponse responseModelRef2, ComplexObject data2, out ComplexModelResponse responseModelOut1, out ComplexModelResponse responseModelOut2) { Console.WriteLine($"{nameof(PingComplexModelOutAndRef)}:"); return(PingComplexModelOutAndRefImplementation( inputModel, ref responseModelRef1, data1, ref responseModelRef2, data2, out responseModelOut1, out responseModelOut2)); }
private static void Main() { var binding = new BasicHttpBinding(); var endpoint = new EndpointAddress(new Uri("http://localhost:5000/service.svc")); var channelFactory = new ChannelFactory <ISampleService>(binding, endpoint); var serviceClient = channelFactory.CreateChannel(); var result = serviceClient.Ping("hey"); Console.WriteLine("Ping method result: {0}", result); var complexModel = new ComplexModelInput { StringProperty = Guid.NewGuid().ToString(), IntProperty = int.MaxValue / 2, ListProperty = new List <string> { "test", "list", "of", "strings" }, DateTimeOffsetProperty = new DateTimeOffset(2018, 12, 31, 13, 59, 59, TimeSpan.FromHours(1)) }; var complexResult = serviceClient.PingComplexModel(complexModel); Console.WriteLine("PingComplexModel result. FloatProperty: {0}, StringProperty: {1}, ListProperty: {2}, DateTimeOffsetProperty: {3}, EnumProperty: {4}", complexResult.FloatProperty, complexResult.StringProperty, string.Join(", ", complexResult.ListProperty), complexResult.DateTimeOffsetProperty, complexResult.TestEnum); serviceClient.VoidMethod(out var stringValue); Console.WriteLine("Void method result: {0}", stringValue); var asyncMethodResult = serviceClient.AsyncMethod().Result; Console.WriteLine("Async method result: {0}", asyncMethodResult); var xmlelement = System.Xml.Linq.XElement.Parse("<test>string</test>"); serviceClient.XmlMethod(xmlelement); Console.ReadKey(); }
public static void Main(string[] args) { Newtonsoft.Json.JsonConvert.DefaultSettings = (() => { var settings = new Newtonsoft.Json.JsonSerializerSettings(); settings.Formatting = Newtonsoft.Json.Formatting.Indented; settings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter { CamelCaseText = true }); return(settings); }); var binding = new BasicHttpBinding(); // todo: why DataContractSerializer not working? var endpoint = new EndpointAddress(new Uri(string.Format("http://{0}:5050/Service.svc", Environment.MachineName))); var channelFactory = new ChannelFactory <ISampleService>(binding, endpoint); var serviceClient = channelFactory.CreateChannel(); var result = serviceClient.Ping("hey"); Console.WriteLine("Ping method result: {0}", result); var complexModel = new ComplexModelInput { StringProperty = Guid.NewGuid().ToString(), IntProperty = int.MaxValue / 2, ListProperty = new List <string> { "test", "list", "of", "strings" }, //DateTimeOffsetProperty = new DateTimeOffset(2018, 12, 31, 13, 59, 59, TimeSpan.FromHours(1)) }; var pingComplexModelResult = serviceClient.PingComplexModel(complexModel); Console.WriteLine($"{nameof(pingComplexModelResult)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(pingComplexModelResult)}\n"); serviceClient.EnumMethod(out var enumValue); Console.WriteLine("Enum method result: {0}", enumValue); var responseModelRef1 = ComplexModelResponse.CreateSample1(); var responseModelRef2 = ComplexModelResponse.CreateSample2(); var pingComplexModelOutAndRefResult = serviceClient.PingComplexModelOutAndRef( ComplexModelInput.CreateSample1(), ref responseModelRef1, ComplexObject.CreateSample1(), ref responseModelRef2, ComplexObject.CreateSample2(), out var responseModelOut1, out var responseModelOut2); Console.WriteLine($"{nameof(pingComplexModelOutAndRefResult)}: {pingComplexModelOutAndRefResult}\n"); Console.WriteLine($"{nameof(responseModelRef1)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(responseModelRef1)}\n"); Console.WriteLine($"{nameof(responseModelRef2)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(responseModelRef2)}\n"); Console.WriteLine($"{nameof(responseModelOut1)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(responseModelOut1)}\n"); Console.WriteLine($"{nameof(responseModelOut2)}:\n{Newtonsoft.Json.JsonConvert.SerializeObject(responseModelOut2)}\n"); serviceClient.VoidMethod(out var stringValue); Console.WriteLine("Void method result: {0}", stringValue); var asyncMethodResult = serviceClient.AsyncMethod().Result; Console.WriteLine("Async method result: {0}", asyncMethodResult); Console.ReadKey(); }