Amazon Ad

Wednesday, 25 September 2013

WCF Could not find a base address that matches scheme https for the endpoint with binding MetadataExchangeHttpBinding. Registered base address schemes are [http].

Hi Guys,

I was facing a problem while invoking a WCF web service which was actually made for SSL (Secure Socket Layer) and runs on the https protocol. My task was to run the webservice without SSL i.e on http.

Here is how i did the same

1. Under bindings tag make sure you comment the line <security mode="Transport" /> i.e,

    <bindings>
      <webHttpBinding>
        <binding name="myBinding" maxBufferSize="2147483647"  maxReceivedMessageSize="2147483647" >
          <readerQuotas  maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647"
            maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
            <!--Commented This line-->
            <!--<security mode="Transport" />-->
        </binding>
      </webHttpBinding>

2. Comment the line <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/> i.e,

<services>
    <service behaviorConfiguration="Mine.Services.MyServiceBehavior" name="Mine.Services.MyService">
        <endpoint address="" binding="webHttpBinding" contract="Mine.Services.IMyService" bindingConfiguration="myBinding">
                <identity>
                <dns value="localhost" />
                </identity>
        </endpoint>
                     <!--Commented This line-->
                <!--<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>-->
    </service>
</services>

And that's it folks, The service now runs on HTTP protocol.

Thanks
Ritesh

Saturday, 14 September 2013

Url Routing For WebForms in ASP.NET 4.5

Hi guys,

Today i am going to tell you how to use URL Routing for ASP.NET Webforms in .net framework 4.0 and 4.5.

Step 1 : Your global.asax file should be like

public class Global : System.Web.HttpApplication
    {

        protected void Application_Start(object sender, EventArgs e)
        {
            RegisterRoutes(RouteTable.Routes);
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }

        protected void Application_BeginRequest(object sender, EventArgs e)
        {

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {

        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {

        }

        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.MapPageRoute("Default", "ritesh", "~/Default.aspx");
            routes.MapPageRoute("DefaultWithIdParam", "ritesh/{id}", "~/Default.aspx");
        }
    }

Step 2 : Create a page Default.aspx if it doesnt exists. Add the following lines on page_load event

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                string data=Page.RouteData.Values["id"].ToString();
            }
            catch (Exception ex)
            {

            }
        }

Step 3: In browser type http://localhost:{port}/ritesh and http://localhost:{port}/ritesh/23. This would return you the page and the data also.

Thanks
Ritesh

Friday, 6 September 2013

How to setup Ruby On Rails on Windows 7 with MySql

Step 1: Install RailsInstaller (railsinstaller-2.2.1), It would create a folder RailsInstaller in the installed directory. Inside this folder go to Ruby1.9.3 folder and further inside bin folder. Right click on any file in the bin folder and select the path from the properties window. Copy this path and now we need to set this path inside PATH environment variable. Go to environment variables and edit PATH and embed the copied path inside the PATH value.


Step 2: Check Ruby and Rails versions. To check Rails version type the command "Rails --version" and press enter it would show you the Rails version. For Ruby use the command "ruby -v" and press enter it would show you the Ruby version. For rails it should be

3.2.13 or 3.2.14

Step 3: Using Ruby interpreter lets you run the ruby statements, You can run the Ruby interpreter using the command "irb". You can write ruby statements and can get the output. For ex. "Hello"*9 would print string "Hello" 9 times in irb.To exit from irb type "quit" and press enter.

Step 4: You can run ruby files (having extension .rb). Create a new file in any text editor and type the following code

myarr=[1,3,4,5,6]

myarr.each do |x|
p x
end

save this file with name "array.rb" and to run this file you need to type the command "ruby  array.rb".

Step 5: Getting started with rails environment. The rails commands are there to help you out in making web applications. To create a new web application project type "rails new firstproject". It would create a folder "firstproject" having default folders and files which are created by default by rails environment.

Step 6: Install MySql 2.8 adapter, Setting up "mysql" and linking it with rails is quite easy, If you follow some simple steps as mentioned. Edit .Gemfile inside the folder firstproject folder and add line gem "mysql". Then edit "database.yml" file present in db folder inside your project folder and add the following lines

development:
adapter: mysql

database: db_firstd

username: root

password: 1234

pool: 5

timeout: 5000

test:

adapter: mysql

database: db_firstt

username: root

password: 1234

pool: 5

timeout: 5000



production:

adapter: mysql

database: db_firstp

username: root

password: 1234

pool: 5

timeout: 5000


Here i am assuming that you have set 1234 as root password for your mysql.

Step 7:  Now we need a C-Connector for mysql, this is important as the rails will try to find the necessary dll to communicate with mysql. You can download it from http://dev.mysql.com/downloads/connector/c/6.0.html.

Step 8: Now since our database.yml file is all set, We can give command so that rails would automatically create the database in mysql database as per the configuration in database.yml file. Give the command

rake db:create

This command would create databases (Development, Production and Test database) in mysql. Now to create a model we would give the command

rails generate model Employee empcode:integer name:string email:string

This command would generate a model, The model is actually a class in RoR which actually represents the table in our database. A model is cretaed so that a table with same name (Employee) with columns (empcode,name,email) can be created in the database.

Step 9: Now we would generate a table using the model class just created by the command. To geneate a table from model we need to migrate it, To migrate the model we need to give the command

rake db:migrate

This would create the table i.e all the unmigrated model classes would be migrated into table using this command.

Step 10: Using scaffold tool is great, It creates CRUD operations by just a single command. Give the command

rails generate scaffold Student regno:string name:string email:string

This would create model, view and contorller classes. But the datbase would not be created. We need to migrate it using the command

rake db:migrate

After this run the command

rails s

to run the project. type http://localhost/students, It would give you all the CRUD operations linked with your mysql database.

How to implement Captcha v3 in ASP.NET

 I was facing an issue of dom parsing in my website. I finally resolved it by using Google Captcha V3. Step 1: Get your keys from https:...