static void Main(string[] args) { var baseAddress = "http://" + Environment.MachineName + ":8081/MyLocalService"; var host = new ServiceHost(typeof(MyLocalService.MyLocalService), new Uri(baseAddress)); var webBinding = new WebHttpBinding(); webBinding.ContentTypeMapper = new RawMapper(); var behaviour = new NewtonsoftJsonBehavior(); host.AddServiceEndpoint(typeof(IMyLocalService), webBinding, "api").Behaviors.Add(behaviour); host.Description.Behaviors.Add(new ServiceMetadataBehavior()); Console.WriteLine("Opening the host"); host.Open(); Console.WriteLine("Now using the client formatter"); var x = HttpWebClient.SendRequest("http://localhost:8081/MyLocalService/api/GetData?value=5", "GET", null, null); Console.ReadLine(); }
internal static PaymentGatewayClient Create(string serverurl, int timeout = 120, WebHttpBehavior behavior = null) { try { WebHttpBinding binding = new WebHttpBinding(); binding.OpenTimeout = TimeSpan.FromSeconds(timeout); binding.CloseTimeout = TimeSpan.FromSeconds(timeout); binding.SendTimeout = TimeSpan.FromSeconds(timeout); binding.ReceiveTimeout = TimeSpan.FromSeconds(timeout); if (serverurl.StartsWith("https")) { binding.Security.Mode = WebHttpSecurityMode.Transport; } ServiceEndpoint svc = new ServiceEndpoint(ContractDescription.GetContract(typeof(ISecurePaymentGateway)), binding, new EndpointAddress(serverurl)); binding.ContentTypeMapper = new NewtonsoftJsonContentTypeMapper(); if (behavior == null) { behavior = new NewtonsoftJsonBehavior { DefaultBodyStyle = WebMessageBodyStyle.Bare, DefaultOutgoingRequestFormat = WebMessageFormat.Json, DefaultOutgoingResponseFormat = WebMessageFormat.Json }; } svc.Behaviors.Add(behavior); PaymentGatewayClient pgc = new PaymentGatewayClient(svc); return(pgc); } catch (Exception e) { Logger.ErrorException("Unable to create PaymentGatewayClient", e); throw; } }
public WCFRestService(string name, NewtonsoftJsonBehavior behavior) : this(name) { this.Behavior = behavior; }