Website ==> Add Web Reference
Adicionar o LINK “http://www.bronzebusiness.com.br/webservices/wscep.asmx”
Mudar o nome do campo “Web reference name:” para WSCep
Clicar em Add Reference
Código C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using WSCep;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
divMSG.InnerHtml = “<center><h3> Digite apenas números </h3></center>”;
}
protected void brnBuscaCep_Click(object sender, EventArgs e)
{
try
{
if (txtCep.Text.Length == 8)
{
WSCep.wscep ws = new WSCep.wscep();
DataSet ds = ws.cep(txtCep.Text);
if (ds.Tables[0].Rows.Count > 0)
{
//ds.Tables[0].Rows[0][0] - Tipo Logradouro (Rua, Av…)
//ds.Tables[0].Rows[0][1] - Rua
//ds.Tables[0].Rows[0][2] - Bairro
//ds.Tables[0].Rows[0][3] - UF
//ds.Tables[0].Rows[0][4] - Cidade
grid.DataSource = ds.Tables[0];
grid.DataBind();
}
else
{
divMSG.InnerHtml = “<center><h1> Não foi encontrado nenhum cep com esse
número </h1></center>”;
}
}
}
catch (Exception)
{
divMSG.InnerHtml = “<center><h1> Não foi encontrado nenhum cep com esse número
</h1></center>”;
}
}
}
Código ASPX
<%@ Page Language=”C#” AutoEventWireup=”true” CodeFile=”Default.aspx.cs” Inherits=”_Default”
%>
<!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>
<script src=”formatacao.js” type=”text/javascript”></script>
<form id=”form1” runat=”server”>
<div id=”divMSG” runat=”server”>
</div>
<asp:TextBox ID=”txtCep” MaxLength=”8” runat=”server” onkeypress=”mascara(this,soNumeros)”
Width=”76px”></asp:TextBox>
<asp:Button ID=”brnBuscaCep” runat=”server” Text=”Buscar CEP”
onclick=”brnBuscaCep_Click” />
<asp:gridview id=”grid” runat=”server”></asp:gridview>
</form>
</body>
</html>
Código JavaScript
function mascara(o,f){
v_obj=o
v_fun=f
setTimeout(“execmascara()”,1)
}
function execmascara(){
v_obj.value=v_fun(v_obj.value)
}
function soNumeros(v){
return v.replace(/\D/g,”“)
}
Espero que ajude =D
Abraço