www.allpaul.com

I needed somewhere to put all this stuff
Welcome to www.allpaul.com Sign in | Join | Help
in Search

Programming

Web-enabled caller id -- part three

In part one I built a VB6 program to monitor my telephone and update a SQL Server database with incoming caller id information. Part 2 focused on building a Web service that exposes methods for reading and manipulating the caller id data. In this part, I will configure a proxy class for accessing my Web service and, finally, build an asp.net page to deliver the caller id information to the Web.

The easiest way to use this Web service is by using Visual Studio.NET to write the page or application that will consume the service. With VS.NET it is as easy as right clicking on the references folder in the solution explorer and choosing "Add Web reference". All that's left is to key in the url of the Web service--in this case http://www.allpaul.com/service.asmx--and after I click the Add Reference Button Viola! The Web service is ready for me to use. In fact, the intellesense in VS.NET even works like you'd expect for objects created via the Web reference.



In this case though, I opted for a far more complicated but less expensive (as it only involves the free .NET SDK download not the full version of Visual Studio.NET) way to create the proxy that is needed to consume the Web service--Using the command line and a few tools included in the .NET SDK.

To begin I opened a command window and navigated to the install path of the .NET sdk. In my case it is C:\WINDOWS\Microsoft.NET\Framework\v1.0.3705. From there I was able to run the two tools I needed to create the proxy. The first, wsdl.exe, to generate a VB.NET soucre file.

wsdl /language:VB http://www.allpaul.com/service.asmx?WSDL

The tool produces a VB source file based on the name of the class it is describing. In this case the file Caller_Id.vb was produced. That's not the end of the command line story though...I still need to compile the VB source file. to do that I'll use the Visual Basic .NET compiler vbc.exe from the same command window.

vbc /t:library Caller_Id.vb /r:System.Web.dll,System.dll,System.Web.Services.dll,System.Xml.dll,System.Data.dll

The /t switch tells the compiler what type of file to produce. In this case a library or .dll is specified. The /r switch indicates which assemblies to reference. There are a number of switches for this tool. To see a complete list type vbc /?.

That's it for the proxy...Well, almost. I still need to put the resulting .dll in to the bin directory of my application.

The output

To display the list of callers I' going to use a Data List. And, since the Web service method Get_Callers returns a Data Set, I'll simply bind that data set to the data source property of my data list. My sub Bind() illustrates this:

Sub Bind()

	Dim myWebSvc as Caller_Id = New Caller_Id()

	Dim ds as DataSet

	ds = myWebSvc.Get_Callers()

	Caller_List.DataSource= ds.Tables("tbl_Caller_Id").DefaultView
	Caller_List.DataBind()

End Sub



My datalist is not your ordinary out of the box datalist though.

I'm not even scratching the surface of the functionality of the datalist or dataset in this example, but I have illustrated a few simple ideas for formatting output and handling events. My desired output is Call_Name (Name or business name of the caller)
Call_Number (The phone number from where the call originated)
Call_Date (Date and time the call was received)

I also want to link the Call_Number to a reverse directory assistance Web site so that I can find out more information about the caller than is provided from the caller id info.

So, the first line of the datalist shows the datalist declaration and sets a few properties...Most notably is the OnItemCommand property which is set to handle only deleting of individual records, but could be used to handle editing as well.

Next, I will start laying out the presentation of the datalist by using an ItemTemplate. The first element of the template is a label to display the Caller_Name item from the dataset.

<asp:Label id="Caller_Name" class="contents" Text='<%# Container.DataItem("Call_Name") %>' runat="server" />  

By binding (The #) the Text property of the label to the Caller_Name item from the dataset I achieve the first line of my desired output.

But, I would also like to delete callers from the list. To do that, I need to add a linkbutton and set its CommandName property to delete. If I was using other commands I would have to handle the Caller_List_ItemCommand sub a little differently, but for simplicity, I'm only going to handle one ItemCommand with it.

<asp:linkbutton id="b1" runat="server" Text="Delete" CommandName = "delete" />

Alright, next I want to display the Call_Number. I mentioned earlier that I'd also like to link to some reverse phone number lookup on the Web in order to find out more information about the caller. The service I found is www.infousa.com. In order to directly link to the lookup feature of their Web site, I need to use this really long convoluted Url:

http://adp.infousa.com/fs?BAS_fssession=&BAS_vendor=0&bas_type=FADA&BAS_page=9&DAT_maxrecords=10&BAS_flag=2&BAS_flag2=1&SCH_origdb=FADP&sch_fullphone=Call_Number

I should also qualify this by saying that there are many of these services on the Internet and most of them are free. And, this one, like all the others, isn't 100% reliable. For instance if the caller has an unlisted or new phone number, most likely there will be no information found. That said, in order to display the phone number and link it to the directory service I will use the hyperlink element:

<asp:hyperlink id="Caller_Number" class="contents" Text=''
              runat="server" NavigateURL='' />

By setting the NavigateURL property to the desired hyperlink and appending the Call_Number to the end of the link, I achieve the desired results.

The final line is similar to the the Call_Name line. I use a label element and bind its Text property to the Call_Date item from the dataset.

<asp:Label id="Caller_Date" class="contents" Text='' runat="server" />

Putting it all together

The complete source code for this part of the project can be found below. Hopefully, this application will be as useful for you as it has been for me and my family. Good luck!

<%@ Import Namespace = "System.Data" %>
<script language="vb" runat="server">

Sub Page_Load()
	
	If Not Page.IsPostBack Then
		Bind()
	End if
	
End Sub

Sub Bind()

	Dim myWebSvc as Caller_Id = New Caller_Id()

	Dim ds as DataSet

	ds = myWebSvc.Get_Callers()

	Caller_List.DataSource= ds.Tables("tbl_Caller_Id").DefaultView
	Caller_List.DataBind()

End Sub



Sub Caller_List_ItemCommand(Sender As Object, e As DataListCommandEventArgs)

	Dim myWebSvc as Caller_Id = New Caller_Id()
	myWebSvc.Delete_Caller(Caller_List.DataKeys(e.Item.ItemIndex))
	Trace.Write(Caller_List.DataKeys(e.Item.ItemIndex))
	Bind()
	
End sub

</script>


<h4>Caller Id Calls</h4>

<form runat="Server">
<asp:DataList runat="server" id="Caller_List" DataKeyField="ID" OnItemCommand="Caller_List_ItemCommand">
	<ItemTemplate>
	  <asp:Label id="Caller_Name" class="contents" Text='<%# Container.DataItem("Call_Name") %>' runat="server" />  
          <asp:linkbutton id="b1" runat="server" Text="Delete" CommandName = "delete" /><br>
	  <asp:hyperlink id="Caller_Number" class="contents" Text='<%# Container.DataItem("Call_Number") %>'
              runat="server" NavigateURL='<%# "http://adp.infousa.com/fs?BAS_fssession=&BAS_vendor=0&bas_type=FADA&BAS_page=9 _
              &DAT_maxrecords=10&BAS_flag=2&BAS_flag2=1&SCH_origdb=FADP&sch_fullphone= _
              " & (DataBinder.Eval(Container.DataItem,"Call_Number")) %>' /><br>
  	  <asp:Label id="Caller_Date" class="contents" Text='<%# Container.DataItem("Call_Date") %>'
              runat="server" /><br><br>
	</ItemTemplate>
</asp:DataList >
</form>

Only published comments... Nov 22 2002, 03:06 PM by paully21
Filed under: ,

About paully21

 

Powered by Community Server (Non-Commercial Edition), by Telligent Systems