Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7887675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:38:31+00:00 2026-06-03T05:38:31+00:00

I have a resource available at http://localhost/resource I do not have any route like

  • 0

I have a resource available at
http://localhost/resource

I do not have any route like
http:/localhost/resource?name=john

but when I try to hit the above URI I get the result of http://localhost/resource. I was expecting a 404.

Any idea why its ignoring ?name=john and match the url ??

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T05:38:33+00:00Added an answer on June 3, 2026 at 5:38 am

    Query string parameters are optional and not “officially” part of the address – it goes from the scheme to the path (via host and port). There are many scenarios where you have one operation at address http://something.com/path, and in the operation code you look at the query string parameters to make some decision. For example, the code below looks for a “format” parameter in the query string which may or may not be passed, and all requests (with or without it) are correctly routed to the operation.

    public class StackOverflow_10422764
    {
        [DataContract(Name = "Person", Namespace = "")]
        public class Person
        {
            [DataMember]
            public string Name { get; set; }
            [DataMember]
            public int Age { get; set; }
        }
        [ServiceContract]
        public class Service
        {
            [WebGet(UriTemplate = "/NoQueryParams")]
            public Person GetPerson()
            {
                string format = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
                if (format == "xml")
                {
                    WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Xml;
                }
                else if (format == "json")
                {
                    WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json;
                }
    
                return new Person { Name = "Scooby Doo", Age = 10 };
            }
        }
        public static void Test()
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            WebServiceHost host = new WebServiceHost(typeof(Service), new Uri(baseAddress));
            host.Open();
            Console.WriteLine("Host opened");
    
            WebClient c = new WebClient();
            Console.WriteLine(c.DownloadString(baseAddress + "/NoQueryParams"));
    
            c = new WebClient();
            Console.WriteLine(c.DownloadString(baseAddress + "/NoQueryParams?format=json"));
    
            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
    }
    

    Update after comments:
    If you want to force the request to contain exactly the parameters specified in the template, then you can use something like a message inspector to validate that.

    public class StackOverflow_10422764
    {
        [DataContract(Name = "Person", Namespace = "")]
        public class Person
        {
            [DataMember]
            public string Name { get; set; }
            [DataMember]
            public int Age { get; set; }
        }
        [ServiceContract]
        public class Service
        {
            [WebGet(UriTemplate = "/NoQueryParams")]
            public Person GetPerson()
            {
                string format = WebOperationContext.Current.IncomingRequest.UriTemplateMatch.QueryParameters["format"];
                if (format == "xml")
                {
                    WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Xml;
                }
                else if (format == "json")
                {
                    WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json;
                }
    
                return new Person { Name = "Scooby Doo", Age = 10 };
            }
    
            [WebGet(UriTemplate = "/TwoQueryParam?x={x}&y={y}")]
            public int Add(int x, int y)
            {
                return x + y;
            }
        }
        public class MyForceQueryMatchBehavior : IEndpointBehavior, IDispatchMessageInspector
        {
            #region IEndpointBehavior Members
    
            public void AddBindingParameters(ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
            {
            }
    
            public void ApplyClientBehavior(ServiceEndpoint endpoint, ClientRuntime clientRuntime)
            {
            }
    
            public void ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
            {
                endpointDispatcher.DispatchRuntime.MessageInspectors.Add(this);
            }
    
            public void Validate(ServiceEndpoint endpoint)
            {
            }
    
            #endregion
    
            #region IDispatchMessageInspector Members
    
            public object AfterReceiveRequest(ref Message request, IClientChannel channel, InstanceContext instanceContext)
            {
                UriTemplateMatch uriTemplateMatch = (UriTemplateMatch)request.Properties["UriTemplateMatchResults"];
    
                // TODO: may need to deal with the case of implicit UriTemplates, or if you want to allow for some query parameters to be ommitted
    
                List<string> uriTemplateQueryVariables = uriTemplateMatch.Template.QueryValueVariableNames.Select(x => x.ToLowerInvariant()).ToList();
                List<string> requestQueryVariables = uriTemplateMatch.QueryParameters.Keys.OfType<string>().Select(x => x.ToLowerInvariant()).ToList();
                if (uriTemplateQueryVariables.Count != requestQueryVariables.Count || uriTemplateQueryVariables.Except(requestQueryVariables).Count() > 0)
                {
                    throw new WebFaultException(HttpStatusCode.NotFound);
                }
    
                return null;
            }
    
            public void BeforeSendReply(ref Message reply, object correlationState)
            {
            }
    
            #endregion
        }
        static void SendRequest(string uri)
        {
            Console.WriteLine("Request to {0}", uri);
            WebClient c = new WebClient();
            try
            {
                Console.WriteLine("  {0}", c.DownloadString(uri));
            }
            catch (WebException e)
            {
                HttpWebResponse resp = e.Response as HttpWebResponse;
                Console.WriteLine("  ERROR => {0}", resp.StatusCode);
            }
        }
        public static void Test()
        {
            string baseAddress = "http://" + Environment.MachineName + ":8000/Service";
            ServiceHost host = new ServiceHost(typeof(Service), new Uri(baseAddress));
            ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(Service), new WebHttpBinding(), "");
            endpoint.Behaviors.Add(new WebHttpBehavior());
            endpoint.Behaviors.Add(new MyForceQueryMatchBehavior());
            host.Open();
            Console.WriteLine("Host opened");
    
            SendRequest(baseAddress + "/NoQueryParams");
            SendRequest(baseAddress + "/NoQueryParams?format=json");
            SendRequest(baseAddress + "/TwoQueryParam?x=7&y=9&z=other");
            SendRequest(baseAddress + "/TwoQueryParam?x=7&y=9");
    
            Console.Write("Press ENTER to close the host");
            Console.ReadLine();
            host.Close();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some dirty resource usage records in t_resourcetable which looks like this resNo
I have a Pyramid app that I've been developing and viewing locally through http://localhost:6543
The error message I get is description The requested resource (/gradebook/WEB-INF/jsp/hello.jsp.jsp) is not available
I am have the following line in my httpd.conf file ProxyPass /something http://localhost:9080/servlet/StubEndpoint?stub=stub the
I have a resource file named filetypes.resx. Some how I figured out to bind
I have couple resource DLLs that I currently load when application starts using following
I have a resource database where resources can belong to different locations. Users and
Say I have a resource (e.g. a filehandle or network socket) which has to
Consider that I have 1 resource and 2 urls (let's say new one and
Is it possible to have multiple resource bundles in spring mvc? I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.