Sunday, May 3, 2015

Confirmation Box for delete button using JQuery

  Resources.ErpRes.Title_Information = Information
Resources.ErpRes.MsgDeleteConfirm = Do you want to delete the record?
function ShowDeleteConfirm(btn, message) {
            var msgTitle;
            var msg;
            msgTitle = '<%= Resources.ErpRes.Title_Information %>';
            msg = message ? message : '<%= Resources.ErpRes.MsgDeleteConfirm %>';
            $("#divConfirmation").html(msg).dialog({
                modal: true,
                height: 150,
                width: 350,
                title: msgTitle,
                resizable: false,
                buttons: {
                    OK: function (e) {
                        $(this).dialog("close");
                        __doPostBack(btn.name, '');
                    },
                    Cancel: function (e) {
                        $(this).dialog("close");
                        if (typeof AfterDeleteConfirmationCancel == "function") {
                            AfterDeleteConfirmationCancel(btn.id);
                        }
                        return false;
                    }
                }
            });
            return false;
        }

Create and consume WCF Restful Service using an HttpClient

Restful Services are getting more and more popular in our days and .NET developers prefer to build them through the Web API Framework, which let’s be honest it sounds right. You need to know though that WCF Framework also provides the support for building services that can be consumed over HTTP requests. This post will show you how easy is to create a WCF Restful service and consume it, either from a simple browser typing the right URL or from another application using an HttpClient.
Open Visual Studio and create a new WCF Service Application named WcfRestfulService. At this very moment, VS has created for you a WCF service using the default binding. You can test it by right clicking the Service1.svc file and view it on browser. We are going to change that service in order to be able to invoke it using HTTP requests.

Change Service1.svc to AdminLoginService.svc.cs.There is also IAdminLoginService.cs

AdminLoginService

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using BusinessLogic;
using System.ServiceModel.Activation;
using System.IO;
using System.Collections.Specialized;
using System.Web;
using System.Data;
using BusinessObject;

namespace AppWcfService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "AdminLoginService" in code, svc and config file together.
    [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, AddressFilterMode = AddressFilterMode.Any)]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class AdminLoginService : IAdminLoginService
    {
        MessageFormat mf = new MessageFormat();
        public List<GETADMINUNIQ> AdminLogin(Stream input)
        {
            string message = string.Empty;
            string login_identity = string.Empty;
            string login_password = string.Empty;
            var streamReader = new StreamReader(input);
            string streamString = streamReader.ReadToEnd();
            streamReader.Close();

            GETADMINUNIQ getadminuniq  = new GETADMINUNIQ();
            GETADMINUNIQlist adminlist = new GETADMINUNIQlist();


            NameValueCollection nvc = HttpUtility.ParseQueryString(streamString);
            login_identity = string.IsNullOrEmpty(nvc["login_identity"]) ? "" : nvc["login_identity"];
            login_password = string.IsNullOrEmpty(nvc["login_password"]) ? "" : nvc["login_password"];
            int LoginID = 0;
            try
            {
                if (login_identity != null && login_password != null)
                {
                    LoginID = user_accountsBL.LOGINaccounts(login_identity, login_password);
                    if (LoginID > 0)
                    {
                        DataTable dtuniq = user_accountsBL.Get_UniqAftrLogin(LoginID);

                        getadminuniq.uniqueid = dtuniq.Rows[0][0].ToString();
                        adminlist.GETADMINUNIQDetailsList.Add(getadminuniq);
                        return adminlist.GETADMINUNIQDetailsList;
                       
                    }
                    else
                    {
                      
                        return adminlist.GETADMINUNIQDetailsList;
                      
                    }
                   
                }
                else
                {
                  
                    return adminlist.GETADMINUNIQDetailsList;
                }

               
            }
            catch
            {
               
                return adminlist.GETADMINUNIQDetailsList;
            }
         
        }


        public MessageFormat FORGOTPASSWORD(Stream input)
        {
            string message = string.Empty;
            string Email = string.Empty;
            string Uniqueid = string.Empty;
            string pwd = string.Empty;
            string fname = string.Empty;
            var streamReader = new StreamReader(input);
            string streamString = streamReader.ReadToEnd();
            streamReader.Close();

            NameValueCollection nvc = HttpUtility.ParseQueryString(streamString);
            Email = string.IsNullOrEmpty(nvc["Email"]) ? "" : nvc["Email"];
            Uniqueid = string.IsNullOrEmpty(nvc["Uniqueid"]) ? "" : nvc["Uniqueid"];


            try
            {
                DataTable dt1 = user_accountsBL.GetPAssword(Email, Uniqueid);
                if (dt1.Rows.Count > 0)
                {
                    //check uniqueid

                    if (dt1.Rows[0][user_accounts.F_uacc_password].ToString() == "-5")
                    {
                        message = "Uniqueid Not Exists";
                        mf.Message = message;
                        return mf;
                    }
                    else if (dt1.Rows[0][user_accounts.F_uacc_password].ToString() == "-1")
                    {
                        message = "Email Not Exists";
                        mf.Message = message;
                        return mf;
                    }
                    else
                    {
                        pwd = dt1.Rows[0][user_accounts.F_uacc_password].ToString();
                        fname = dt1.Rows[0][user_accounts.F_upro_first_name].ToString();

                        string msg = " <b> Dear " + fname + ",</b> <br> <br> <br> </t> Your Password is :" + " " + pwd + " <br> <br> <b> Best Regards</b>,<br><br> <b> Admin</b>";
                        bool res = user_profilesBL.SendEmail("PASSWORD RECOVERY", msg, Email);
                        if (res == true)
                        {
                            message = "Success";
                            mf.Message = message;
                            return mf;
                        }
                        else
                        {
                            message = "Error";
                            mf.Message = message;
                            return mf;
                        }
                    }
                }
                else
                {
                    message = "Not Exists";
                    mf.Message = message;
                    return mf;
                }

               
              
            }
            catch
            {
                message = "Error";
                mf.Message = message;
                return mf;
            }
        }
    }
}


IAdminLoginService

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
using System.IO;

namespace AppWcfService
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IAdminLoginService" in both code and config file together.
    [ServiceContract]
    public interface IAdminLoginService
    {
      
        [OperationContract]
        [WebInvoke(Method = "POST",
                    UriTemplate = "AdminLogin",
                    ResponseFormat = WebMessageFormat.Json,
                    BodyStyle = WebMessageBodyStyle.Bare)]
        List<GETADMINUNIQ> AdminLogin(Stream input);


        [OperationContract]
        [WebInvoke(Method = "POST",
                    UriTemplate = "FORGOTPASSWORD",
                    ResponseFormat = WebMessageFormat.Json,
                    BodyStyle = WebMessageBodyStyle.Bare)]
        MessageFormat FORGOTPASSWORD(Stream input);

    }


    [DataContract]
    public class GETADMINUNIQ
    {
        [DataMember]
        public string uniqueid 
        { get; set; }
       
    }


    [DataContract]
    public class GETADMINUNIQlist 
    {
        List<GETADMINUNIQ> _getadminli = new List<GETADMINUNIQ>();
        [DataMember]
        public List<GETADMINUNIQ> GETADMINUNIQDetailsList  
        {
            get { return _getadminli; }
            set { _getadminli = value; } 
        }
    }

  [DataContract]
    public class MessageFormat
    {      
        [DataMember]
        public string Message
        { get; set; }

    }
}

Web.Config

<?xml version="1.0"?>
<configuration>
  <appSettings>
  </appSettings> 
  <connectionStrings>
    <add name="CONNECTIONSTRING" connectionString="Data Source=192.168.1.110;User ID=sa;Password=Ecreations_123;Initial Catalog=HMS_DEV_MVC_DEMO;Integrated Security=false;Persist Security Info=True;Connect Timeout=300; pooling='true'; Max Pool Size=90;" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <identity impersonate="false" />
    <httpRuntime maxRequestLength="2073741824" requestPathInvalidCharacters=""  useFullyQualifiedRedirectUrl="true" executionTimeout="14400"/>  
    <compilation debug="true" targetFramework="4.0"/>
    <authentication mode="Windows"/>
    <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>  
  </system.web>
  <system.webServer>
    <security>
      <requestFiltering>
        <requestLimits maxAllowedContentLength="2073741824"/>
      </requestFiltering>
    </security>
  </system.webServer>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
    <services>
      <service behaviorConfiguration="AppWcfService.AdminLoginServiceBehavior" name="AppWcfService.AdminLoginService">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" contract="AppWcfService.IAdminLoginService">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="default">
          <dataContractSerializer maxItemsInObjectGraph="2147483647" />
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>      
        <behavior name="AppWcfService.AdminLoginServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>      
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding name="RestBinding" maxReceivedMessageSize="2147483647" sendTimeout="00:10:00" maxBufferPoolSize="1073741824">
          <readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"  maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
          <security mode="None">
          </security>
        </binding>
      </webHttpBinding>
    </bindings> 
  </system.serviceModel>
</configuration>

Difference between WCF and Web service

Web service is a part of WCF. WCF offers much more flexibility and portability to develop a service when comparing to web service. Still we are having more advantages over Web service; following table provides detailed difference between them.

Advantages of WCF

1)    WCF is interoperable with other services when compared to .Net Remoting where the client and service have to be .Net.
     2)    WCF services provide better reliability and security in compared to ASMX web services.
     3)    In WCF, there is no need to make much change in code for implementing the security model and changing the binding. Small changes in the configuration will make your requirements.
     4)    WCF has integrated logging mechanism, changing the configuration file settings will provide this functionality. In other technology developer has to write the code.

What is WCF (windows communication foundation) Service?

Windows Communication Foundation (Code named Indigo) is a programming platform and runtime system for building, configuring and deploying network-distributed services. It is the latest service oriented technology; Interoperability is the fundamental characteristics of WCF. It is unified programming model provided in .Net Framework 3.0. WCF is a combined feature of Web Service, Remoting, MSMQ and COM+. WCF provides a common platform for all .NET communication.

WCF - Overview

WCF stands for Windows Communication Foundation. The elementary feature of WCF is interoperability. It is one of the latest technologies of Microsoft that is used to build service-oriented applications. Based on the concept of message-based communication, in which an HTTP request is represented uniformly, WCF makes it possible to have a unified API irrespective of diverse transport mechanisms.
WCF was released for the first time in 2006 as a part of the .NET framework with Windows Vista, and then got updated several times. WCF 4.5 is the most recent version that is now widely used.
A WCF application consists of three components:
  • WCF service,
  • WCF service host, and
  • WCF service client.
WCF platform is also known as the Service Model.

Fundamental Concepts of WCF

Message

This is a communication unit that comprises of several parts apart from the body. Message instances are sent as well as received for all types of communication between the client and the service.

Endpoint

It defines the address where a message is to be sent or received. It also specifies the communication mechanism to describe how the messages will be sent along with defining the set of messages. A structure of an endpoint comprises of the following parts:
  • Address - Address specifies the exact location to receive the messages and is specified as a Uniform Resource Identifier (URI). It is expressed as scheme://domain[:port]/[path]. Take a look at the address mentioned below:
    net.tcp://localhost:9000/ServiceA
    Here, 'net.tcp' is the scheme for the TCP protocol. The domain is 'localhost' which can be the name of a machine or a web domain, and the path is 'ServiceA'.
  • Binding - It defines the way an endpoint communicates. It comprises of some binding elements that make the infrastructure for communication. For example, a binding states the protocols used for transport like TCP, HTTP, etc., the format of message encoding, and the protocols related to security as well as reliability.
  • Contracts - It is a collection of operations that specifies what functionality the endpoint exposes to the clinet. It generally consists of an interface name.

Hosting

Hosting from the viewpoint of WCF refers to the WCF service hosting which can be done through many available options like self-hosting, IIS hosting, and WAS hosting.

Metadata

This is a significant concept of WCF, as it facilitates easy interaction between a client application and a WCF service. Normally, metadata for a WCF service is generated automatically when enabled, and this is done by inspection of service and its endpoints.

WCF Client

A client application that gets created for exposing the service operations in the form of methods is known as a WCF client. This can be hosted by any application, even the one that does service hosting.

Channel

Channel is a medium through which a client communicates with a service. Different types of channels get stacked and are known as Channel Stacks.

SOAP

Although termed as ‘Simple Object Access Protocol’, SOAP is not a transport protocol; instead it is an XML document comprising of a header and body section.

Advantages of WCF

  • It is interoperable with respect to other services. This is in sharp contrast to .NET Remoting in which both the client and the service must have .Net.
  • WCF services offer enhanced reliability as well as security in comparison to ASMX (Active Server Methods) web services.
  • Implementing the security model and binding change in WCF do not require a major change in coding. Just a few configuration changes is required to meet the constraints.
  • WCF has built-in logging mechanism whereas in other technologies, it is essential to do the requisite coding.
  • WCF has integrated AJAX and support for JSON (JavaScript object notation).
  • It offers scalability and support for up-coming web service standards.
  • It has a default security mechanism which is extremely robust.

Software Products for Accounting,Content Management,Bulk SMS & EMAIL



Shop Management Software(Accounting & Inventory) : 



Bulk SMS & EMAIL Software : 


CMS Website for Overseas education consultancy :
username : superadmin
password : password

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...