public void DomainServiceHost_DefaultBehaviors()
        {
            DomainServiceHost host = this.CreateHost <DomainServiceHost>();

            // Verify we require ASP.NET compat mode.
            var aspNetCompatModeAtt = host.Description.Behaviors.Find <AspNetCompatibilityRequirementsAttribute>();

            Assert.IsNotNull(aspNetCompatModeAtt, "ASP.NET compat mode behavior not found.");
            Assert.AreEqual(AspNetCompatibilityRequirementsMode.Required, aspNetCompatModeAtt.RequirementsMode);

            // Verify service behavior defaults.
            var serviceBehaviorAtt = host.Description.Behaviors.Find <ServiceBehaviorAttribute>();

            Assert.IsNotNull(serviceBehaviorAtt, "Service behavior not found.");
            Assert.AreEqual(AddressFilterMode.Any, serviceBehaviorAtt.AddressFilterMode, "Unexpected address filter mode.");
            Assert.IsTrue(serviceBehaviorAtt.IncludeExceptionDetailInFaults, "Exception details are expected to be included in faults.");

            // Verify we that for a service with just a HTTP base address, only HttpGetEnabled is true.
            var metadataAtt = host.Description.Behaviors.Find <ServiceMetadataBehavior>();

            Assert.IsNotNull(metadataAtt, "Service metadata behavior not found.");
            Assert.IsTrue(metadataAtt.HttpGetEnabled, "HTTP GET disabled.");
            Assert.IsFalse(metadataAtt.HttpsGetEnabled, "HTTPS GET enabled.");

            // Verify we that for a service with just a HTTP base address, only HttpGetEnabled is true.
            host        = this.CreateHost <DomainServiceHost>(new Uri("https://localhost/MyDomainService.svc"));
            metadataAtt = host.Description.Behaviors.Find <ServiceMetadataBehavior>();
            Assert.IsNotNull(metadataAtt, "Service metadata behavior not found.");
            Assert.IsFalse(metadataAtt.HttpGetEnabled, "HTTP GET enabled.");
            Assert.IsTrue(metadataAtt.HttpsGetEnabled, "HTTPS GET disabled.");
        }
예제 #2
0
        private static void StartServerAndWaitForKey(Uri uri, Type type)
        {
            if (DomainServicesSection.Current.Endpoints.Count == 1)
            {
                DomainServicesSection.Current.Endpoints.Add(
                    new ProviderSettings("soap", typeof(SoapXmlEndpointFactory).AssemblyQualifiedName));
                DomainServicesSection.Current.Endpoints.Add(
                    new ProviderSettings("json", typeof(JsonEndpointFactory).AssemblyQualifiedName));
            }

            using (var host = new DomainServiceHost(type, uri))
            {
                //other relevent code to configure host's end point etc
                if (host.Description.Behaviors.Contains(typeof(AspNetCompatibilityRequirementsAttribute)))
                {
                    var compatibilityRequirementsAttribute = host.Description.Behaviors[typeof(AspNetCompatibilityRequirementsAttribute)] as AspNetCompatibilityRequirementsAttribute;
                    compatibilityRequirementsAttribute.RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed;
                }

                host.Open();

                Console.WriteLine($"DomainService {type.Name} running at {uri}");
                Console.WriteLine("Press ENTER to exit");
                Console.ReadLine();
                host.Close();
            }
        }
        public void DomainServiceHost_SecureEndpoint()
        {
            DomainServiceHost host = this.CreateHost <DomainServiceHost, MySecureDomainService>(new Uri[] {
                new Uri("http://localhost/MySecureDomainService.svc"),
                new Uri("https://localhost/MySecureDomainService.svc")
            });

            Assert.AreEqual(1, host.BaseAddresses.Count);
            Assert.AreEqual(Uri.UriSchemeHttps, host.BaseAddresses[0].Scheme);
        }
        public void DomainServiceHost_DefaultEndpoints()
        {
            DomainServiceHost host = this.CreateHost <DomainServiceHost>();
            var eps = host.Description.Endpoints;

            Assert.AreEqual(1, eps.Count, "Unexpected amount of endpoints.");

            // REST w/ binary endpoint.
            Assert.IsTrue(eps.Any(ep => ep.Address.Uri.OriginalString.EndsWith("/binary")));
        }
        public override IEnumerable<ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost)
        {
            List<ServiceEndpoint> endpoints = base.CreateEndpoints(description, serviceHost).ToList();
            foreach (ServiceEndpoint endpoint in endpoints)
            {
                WebHttpBehavior behavior = endpoint.Behaviors.Find<WebHttpBehavior>();
                if (behavior != null)
                {
                    behavior.HelpEnabled = true;
                }
            }

            return endpoints;
        }
        public void DomainServiceHost_DefaultEndpoints()
        {
            DomainServiceHost host = this.CreateHost <DomainServiceHost>();
            var eps = host.Description.Endpoints;

            Assert.AreEqual(2, eps.Count, "Unexpected amount of endpoints.");

            // REST w/ binary endpoint.
            Assert.IsTrue(eps.Any(ep => ep.Address.Uri.OriginalString.EndsWith("/binary")));

            // REST w/ JSON endpoint.
            Assert.IsTrue(eps.Any(ep => ep.Address.Uri.OriginalString.EndsWith("/json")));

            Assert.AreEqual(1, CustomJsonEndpointFactory.LastParameters.Count, "Incorrect number of parameters were retrieved from config.");
        }
        public void CreateEndpointsTest()
        {
            DomainServiceHost sh = new DomainServiceHost(typeof(MyDomainService), new Uri("http://foo.com/bar"), new Uri("https://foo.com/bar"), new Uri("net.tcp://bar.baz.com"));
            TracingDomainServiceEndpointFactory target = new TracingDomainServiceEndpointFactory();

            target.Name = "tracing";
            target.Parameters["maxEntries"] = "123";
            IEnumerable <ServiceEndpoint> actual = target.CreateEndpoints(null, sh);

            Assert.IsTrue(123 == InMemoryTraceListener_Accessor.MaxEntries);
            Assert.IsNotNull(actual);
            ServiceEndpoint[] endpoints = actual.ToArray();
            Assert.IsTrue(endpoints.Length == 2);
            Assert.IsTrue(endpoints[0].Address.Uri.OriginalString == "http://foo.com/bar/tracing");
            Assert.IsInstanceOfType(endpoints[0].Binding, typeof(WebHttpBinding));
            Assert.IsTrue(((WebHttpBinding)(endpoints[0].Binding)).Security.Mode == WebHttpSecurityMode.None);
            Assert.IsTrue(endpoints[1].Address.Uri.OriginalString == "https://foo.com/bar/tracing");
            Assert.IsInstanceOfType(endpoints[1].Binding, typeof(WebHttpBinding));
            Assert.IsTrue(((WebHttpBinding)(endpoints[1].Binding)).Security.Mode == WebHttpSecurityMode.Transport);
        }
        public void DomainServiceHost_GetService()
        {
            DomainServiceHost host = this.CreateHost <DomainServiceHost>();

            using (StringWriter writer = new StringWriter())
            {
                HttpRequest  request  = new HttpRequest("c:\\temp\\test.txt", "http://localhost/test.txt", "");
                HttpResponse response = new HttpResponse(writer);
                HttpContext.Current = new HttpContext(request, response);
                Assert.AreSame(HttpContext.Current, host.GetService(typeof(HttpContext)));

                HttpContextBase wrapper = (HttpContextBase)host.GetService(typeof(HttpContextBase));
                Assert.IsNotNull(wrapper);
            }

            ExceptionHelper.ExpectArgumentNullException(delegate
            {
                host.GetService(null);
            }, "serviceType");
        }
예제 #9
0
        public void Start()
        {
            _host = new DomainServiceHost(typeof(CityDomainService), _uri);

            //other relevent code to configure host's end point etc
            if (_host.Description.Behaviors.Contains(typeof(AspNetCompatibilityRequirementsAttribute)))
            {
                var compatibilityRequirementsAttribute = _host.Description.Behaviors[typeof(AspNetCompatibilityRequirementsAttribute)] as AspNetCompatibilityRequirementsAttribute;
                compatibilityRequirementsAttribute.RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed;
            }

            _host.Open();
            switch (DomainClient)
            {
            case DomainClientType.HttpBinary:
                throw new NotImplementedException();
                //DomainContext.DomainClientFactory = new OpenRiaServices.Client.PortableWeb.WebApiDomainClientFactory();
                break;

            case DomainClientType.HttpBinaryWinHttp:
                throw new NotImplementedException();

                /*DomainContext.DomainClientFactory = new OpenRiaServices.Client.PortableWeb.WebApiDomainClientFactory()
                 * {
                 *  HttpClientHandler = new WinHttpHandler() { }
                 * };*/
                break;

            case DomainClientType.WcfBinary:
                DomainContext.DomainClientFactory = new OpenRiaServices.Client.Web.WebDomainClientFactory();
                break;

            default:
                throw new NotImplementedException();
            }

            _ctx = new CityDomainContext(_clientUri);
            CityDomainService.GetCitiesResult = CreateValidCities(NumEntities).ToList();

            _ctx.LoadAsync(_ctx.GetCitiesQuery()).GetAwaiter().GetResult();
        }
예제 #10
0
        public override IEnumerable <ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost)
        {
            List <ServiceEndpoint> endpoints = base.CreateEndpoints(description, serviceHost).ToList();

            foreach (ServiceEndpoint endpoint in endpoints)
            {
                WebHttpBehavior behavior = endpoint.Behaviors.Find <WebHttpBehavior>();
                if (behavior != null)
                {
                    behavior.HelpEnabled = true;
                }
            }

            return(endpoints);
        }
예제 #11
0
 public override IEnumerable <ServiceEndpoint> CreateEndpoints(DomainServiceDescription description, DomainServiceHost serviceHost, ContractDescription contractDescription)
 {
     CustomJsonEndpointFactory.LastParameters = this.Parameters;
     return(base.CreateEndpoints(description, serviceHost, contractDescription));
 }