Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I got the following error

GET http://localhost:61832/Service1.svc/data?ColumnName=FNAME 400 (Bad Request)

while executing the below javascript code:

JavaScript
$(document).ready(function () {
    $('.filter').click(function () {

        var pos = $(this).position();
        var width = $(this).outerWidth();
        var height = $(this).outerHeight();
        var colName = $(this).attr("alt");

        jQuery.support.cors = true;

        $.ajax({

            type: "GET",
            url: "http://localhost:61832/Service1.svc/data?ColumnName=" + colName,
            processData: false,
            contentType: "application/json; charset=utf-8",
            dataType: "json",

            success: function (response) {

              // doing something

            },
            error: function (xhr, status, error) {
                alert(error);
            }
        });

    });
    $(document).mouseup(function (e) {
        var container = $("#divFilterList");

        if (container.has(e.target).length === 0) {
            container.detach();
        }
    });
});



I have got another page that contains the same code with different hostname and is running fine. What can be the reason?? Kindly help!!

Edit: Here is the system.serviceModel of web.config file

XML
<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="WebBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="NoSecurity">
          <security mode="None"/>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service name="GRDIVIEW EXCEL FILTER.Service1">
        <endpoint address="" behaviorConfiguration="WebBehavior" binding="webHttpBinding" contract="GRDIVIEW EXCEL FILTER.IService1"/>
      </service>
    </services>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>


Here is the IService1.cs file:

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Web;

namespace GRIDVIEW_EXCEL_FILTER
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        [WebGet(UriTemplate = "/data?ColumnName={strColumnName}", ResponseFormat = WebMessageFormat.Json)]
        FilterValueSet[] GetDistinctValue(string strColumnName);
    }
}



and here the service1.svc.cs file:

C#
using System;
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;
using Oracle.DataAccess.Client;
using Oracle.DataAccess.Types;
using System.Configuration;
using System.Data;

namespace GRIDVIEW_EXCEL_FILTER
{
    public class Service1 : IService1
    {
        public FilterValueSet[] GetDistinctValue(string strColumnName)
        {
            OracleConnection connection = null;

            try
            {

                connection = new OracleConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());

                string strOracle = string.Empty;
                switch (strColumnName) // This is the column name in the GridView defined
                {
                    //do something;
                }
               
                OracleCommand command = new OracleCommand();
                command.CommandText = strOracle;
                command.Connection = connection;

                command.Connection.Open();

                OracleDataReader dataReader = command.ExecuteReader(CommandBehavior.CloseConnection);

                IList<FilterValueSet> filterValueList = new List<FilterValueSet>();

                while (dataReader.Read())
                {
                    filterValueList.Add(new FilterValueSet
                    {
                        Id = dataReader[0].ToString(),
                        Value = dataReader[1].ToString()
                    });
                }
                connection.Close();

                return filterValueList.ToArray<FilterValueSet>();
            }
            catch (Exception ex)
            {
               //do something;
            }
        }
    }
    public class FilterValueSet
    {
        public string Id { get; set; }
        public string Value { get; set; }
    }
}


What I have tried:

i have searched the web for possible answer...i am not quite hands on for javascript....
Posted
Updated 5-May-16 20:26pm
v4
Comments
Richard MacCutchan 4-May-16 7:47am    
Is the webserver running on your local PC on port 61832?
planetz 4-May-16 7:56am    
yes...the one which is giving error...
Richard MacCutchan 4-May-16 9:24am    
Have you tried entering that HTML in your webbrowser to see that it is all valid? Are you sure all parts of that request are spelled correctly?
planetz 6-May-16 0:52am    
the one which is running http://localhost:1609/Service1.svc/data?ColumnName=FNAME gives some id and value pairs on the web page.
the one which is not running http://localhost:61832/Service1.svc/data?ColumnName=FNAME is not giving that output...

Also on running the service page directly for the 'good' project redirects automatically to the .aspx page that uses it. While running .svc file from 'bad' project says "You have created a service. To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:

svcutil.exe http://localhost:61832/Service1.svc?wsdl

This will generate a configuration file and a code file that contains the client class. Add the two files to your client application and use the generated client class to call the Service."
Richard Deeming 4-May-16 13:56pm    
Based on the error, the path you're trying to access is invalid. How you fix that will depend on your service and its configuration, neither of which we can see.

Click "Improve question" and update your question with the relevant parts of your service and your web.config file.

1 solution

I have written this line wrong in web.config file:
C#
<service name="GRDIVIEW EXCEL FILTER.Service1">

this should be:
C#
<service name="GRDIVIEW_EXCEL_FILTER.Service1">

the namespace....not the project name...
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900