Wednesday, October 6, 2010

Accsess The Magento Core API With Dot net technologies

Magento is one of the most popular e-commerce platforms.which based  on PHP and Mysql.Magento Core API supports both SOAP and XML RPC protocols. The API is permission based and allows access to the Customer, Catalog and Order modules of Magento. Please reference the documentation for more information.
This article I am going to explaining How to access magento web service from Dot net Technologies .
we can access magento soap api with following url.
http://mymagento.com/api/v2_soap?wsdl (You can see wsdl definition by typing this url in web browser).
So let see how to display Magento customer list in my WindowsFormsApplication project.
To consume to the magento web service in our application we should add web Reference by rigth click on solution .

In the web reference dialog box type the magento web service URL (http://mymagento.com/api/v2_soap?wsdl) and click Go button then available service method display as following screen.
Then we can change the web service name and click Add Refference button.

 By doing above steps,we can generate  the web service proxy .
C# code to retrieve  customer list.
 using Magento.com.mymagento

public void  showCustomrs(){
   MagentoService ms = new MagentoService();
   string sesion= ms.login("Dinesh", "123456");
   filters myfilter=new filters();//filter criteriya
   customerCustomerEntity[] cusls= ms.customerCustomerList(sesion,myfilter);//get customers
   dgCutomer.ItemsSource = cusls; //display in grid
}









Saturday, August 7, 2010

How to Create WCF Application

Select WCF Service Application from New Project window in Visual Studio and name the project as MyWCFService

Add WCF Service to the “MyWCFService” project and named as Myservice.svc

What is Service Contracts ?
Describe which operations the client can perform on the service. There are two types of Service Contracts.
ServiceContract - This attribute is used to define the Interface.
OperationContract - This attribute is used to define the method inside Interface.

IMyService.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.Text;


[ServiceContract]

public interface IService

{

    [OperationContract]

     Employeee GetEmployee(int id);// service method

      

}

Then we can implement above interface

MyService.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Runtime.Serialization;

using System.ServiceModel;

using System.Text;

using Common;

    public class MyService: IMyService

    {


        #region MyService Members


        public Employeee GetEmployee(int id)//service method implimentation

        {

 Employeee emp = new Employeee { EmpId = Guid.NewGuid(),Name="Dinesh",Type=EmployeeTypesEnum.Accounter };

                     return emp;

        }


        #endregion

    }

What is Data contracts?

Define which data types are passed to and from the service. WCF defines implicit contracts for built-in types such as int and string, but we can easily define explicit opt-in data contracts for custom types.
Types Supported by the Data Contract Serializer

There are two types of Data Contracts.
DataContract - attribute used to define the class
DataMember - attribute used to define the properties

Add Class Employee to the solution

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Runtime.Serialization;

using System.ServiceModel;


    [DataContract]

    public class Employeee

    {

        [DataMember]

        public Guid EmpId { get; set; }

        [DataMember]

        public string Name { get; set; }

        [DataMember]

        public EmployeeTypesEnum Type { set; get; }

    }

How To Pass Enum with WCF services?

To pass Enum the Data contracts should be define with EnumMember() attributes.


using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Runtime.Serialization;


 [DataContract]

   public enum EmployeeTypesEnum

    {

    [EnumMember()]


          Administrator = 0,


    [EnumMember()]


          Manager = 1,


    [EnumMember()]


          Accounter = 2


}

How to Test WCF application ?

WCF service can test with WCF Test Client (WcfTestClient.exe) by  execute WcfTestClient.exe commond in Visual Studio Command prompt .
 

Saturday, April 10, 2010

VS 2008 service pack offline version

With fallowing link we can download VS2008 SP1 offline version and it is a .iso file so we need to burn it in to DVD and install with DVD ROM.
VS 2008 SP1

Thursday, March 11, 2010

COPY EXCELL SHEET DATA TO MS SQL DATA BASE WITH C#.NET

using System.Data.SqlClient;
using System.Data;
using System.Data.OleDb;

public class CopyExcellToMSSql
{
string _sourceConnectionString=;
string _destinationConnectionString;

public CopyExcellToMSSql(string sourceConnectionString,
string destinationConnectionString)
{
_sourceConnectionString =
sourceConnectionString;
_destinationConnectionString =
destinationConnectionString;
}

public void CopyTable(string Ftable,string Ttable)
{
using (OleDbConnection source =
new OleDbConnection(_sourceConnectionString))
{
string sql = string.Format("SELECT * FROM [{0}]",
Ftable);

OleDbCommand command = new OleDbCommand(sql, source);

source.Open();
IDataReader dr = command.ExecuteReader();

using (SqlBulkCopy copy =
new SqlBulkCopy(_destinationConnectionString))
{
copy.DestinationTableName = Ttable;
copy.WriteToServer(dr);
}
}
}
}

Calling above method
public void CopyData{
string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\Documents and Settings\\Dinesh\\Desktop\\D-Garment\\work detailes.xls; Extended Properties=""Excel 8.0;HDR=Yes"";";

string sqlConnectionString ="Data Source=KIT\MYSERVER; Initial Catalog=EMS;User ID=ems; Password=ems123";

CopyExcellToMSSql cpLogic = new CopyExcellToMSSql(excelConnectionString, sqlConnectionString);
cpLogic.CopyTable("Employee$", "TempEMPLOYEE");// Employee is work sheet and "TempEMPLOYEE" is table

Wednesday, February 17, 2010

Insert Multiple Rows to Table in SQL

INSERT INTO [tabale1]
([col1]
,[col2]
,[col3]
,[col4])

(SELECT '11','1','1','1' UNION ALL 
SELECT '22','2','2','2')