Showing posts with label WebService. Show all posts
Showing posts with label WebService. Show all posts

August 1, 2011

OFAC SDN WEB SERVICE

This web services is created for Money Transfer Businesses in US to meet the requirements of the US Treasury Department s Office of Foreign Asset Control (OFAC).OFAC restricts transactions with specific countries, organizations and individuals. The Office of Foreign Assets Control (OFAC) of the US Department of the Treasury administers and enforces economic and trade sanctions based on US foreign policy and national security goals against targeted foreign countries, terrorists, international narcotics traffickers, and those engaged in activities related to the proliferation of weapons of mass destruction. OFAC acts under Presidential wartime and national emergency powers, as well as authority granted by specific legislation, to impose controls on transactions and freeze foreign assets under US jurisdiction. This WebService checks in SDNLIST Provided by OFAC ,for the Blocked Person (Both FirstName and Last Name) in Method (CheckBlockedNames)or the Corporation (Only Last Name) in Method (CheckBlockedEntities)


 In Method( CheckBlockedNamesWithTolerance) Web Service returns the 
List of Matching Individuals and Corporation within the tolerance given by the web service client by calculating the LEVENSHTEIN distance

WEBSERVICE END POINT : 


http://184.168.209.81/SDNWebService/CheckSDNBlockedPerson.asmx


wsdl document link


http://184.168.209.81/SDNWebService/CheckSDNBlockedPerson.asmx?WSDL



Below is the Test client written to Use all 3 methods of the above web service


1.) Add the web Reference of the web Service  URL 




Default.aspx.cs 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebReference;
public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
       CheckSDNBlockedPerson OBJ = new CheckSDNBlockedPerson();
     
        //Use Methoid to know if the Individual is in blocked list provided by OFAC Dept
       bool result = OBJ.CheckBlockedNames("Khantibhal", "Patel");


        if (result ==true )
        {
            Response.Write("Khantibhai patel is black listed person <br/>");
        }
        else
        {
            Response.Write("Khantibhai patel is not black listed person <br/>");


        }




        //Use Methoid to know if the Corporation is in blocked list provided by OFAC Dept
        bool result1 = OBJ.CheckBlockedEntities("POPULAR FRONT FOR THE LIBERATION OF PALESTINE");


        if (result1 == true)
        {
            Response.Write("POPULAR FRONT FOR THE LIBERATION OF PALESTINE is balck listed Entity <br/>");
        }
        else
        {
            Response.Write("POPULAR FRONT FOR THE LIBERATION OF PALESTINE is not balck listed Entity <br/>");


        }




        //Use Methoid to get the matching blacklisted names with the tolerance specified


        BLOCKLISTTolerance [] OBJLIST= OBJ.CheckBlockedNamesWithTolerance("KHANTIbHAI", "PATe", 6);
       foreach (BLOCKLISTTolerance I in OBJLIST)
       {


           Response.Write(I.FirstName);
           Response.Write("  ");
           Response.Write(I.LastName );
           Response.Write("  ");
           Response.Write(I.Tolerance);
           Response.Write("<BR/>");




       }




    }
}


Below will be the o/p


March 25, 2011

WebService Code Example

Below WebService Example gets the Stock Price based on the CompanyCode Entered by the user

1.) Add an asmx page into solution by choosing the webservice Template
2.) Write the code in StockQuotewebService.cs file in APP_CODE Folder


StockQuotewebService.cs

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Services;


/// <summary>
/// Summary description for StockQuotewebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
// [System.Web.Script.Services.ScriptService]
public class StockQuotewebService : System.Web.Services.WebService {


    public StockQuotewebService () {


        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }


    public class SecurityInfo
    {
        public String CompnanyCode;
        public String CompnanyName;
        public double StockPrice;


        public SecurityInfo()
        {
            CompnanyCode = "";
            CompnanyName = "";
            StockPrice = 0.0;
        }


    }


    //Private Method for the webService
    public SecurityInfo GetInformation(String Code)
    {
        Random rObj = new Random();
        SecurityInfo obj = new SecurityInfo();
        obj.CompnanyCode = Code;
        obj.StockPrice = rObj.Next(1200);
        obj.CompnanyName = Code + "  " + "PVT LIMITED";


        return obj;




    }


    //Exposed Method from the web service
    [WebMethod]
    public SecurityInfo GetComapnyPrice(string code)
    {


       SecurityInfo result= GetInformation(code);
       return result;
    }




}


StockQuotewebService.asmx

<%@ WebService Language="C#" CodeBehind="~/App_Code/StockQuotewebService.cs" Class="StockQuotewebService" %>

After Executing this webservice you ll see the below Interface to test the Service



                
click on Invoke will show you the below result

                    
3.) Right click on root folder in Solution Explorer add App_WebReference choose the above created
     webservice and give reference name in my case it is 'localhost' ,click on  'Add Reference'
4.) Add an .aspx page to consume the above web service

Below is the code to Consume Above Web Service


UseStockPricewebService.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="UseStockPricewebService.aspx.cs" Inherits="UseStockPricewebService" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Company code:<asp:TextBox ID="txtCode" runat="server"></asp:TextBox><br />
        <asp:Button ID="btnGetQuote" runat="server" Text="GETSTOCKQUOTE" 
            onclick="btnGetQuote_Click" /><br />
        
        Code<asp:Label ID="lblCode" runat="server" Text=""></asp:Label><br />
        Name<asp:Label ID="lblName" runat="server" Text=""></asp:Label><br />
        Price<asp:Label ID="lblPrice" runat="server" Text=""></asp:Label><br />
    </div>
    </form>
</body>
</html>



UseStockPricewebService.aspx.cs

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using localhost;
public partial class UseStockPricewebService : System.Web.UI.Page
{
    StockQuotewebService wsObj = new StockQuotewebService();
    protected void Page_Load(object sender, EventArgs e)
    {




    }
    protected void btnGetQuote_Click(object sender, EventArgs e)
    {
        StockQuotewebService .SecurityInfo obj = wsObj.GetComapnyPrice(txtCode.Text);
        lblCode.Text ="   : "+ obj.CompnanyCode;
        lblName.Text = "   : " + obj.CompnanyName;
        lblPrice.Text = "   : " + obj.StockPrice.ToString();


    }
}




Below is the o/p when you run the above seStockPricewebService.aspx 

Click on GETSTOCKQUOTE Button 'll see the below o/p