Sunday, June 25, 2017   Login
You are here: Example Code » How to extend IWeb for your own modules  
Tutorial: How to extend IWeb for your own modules (Survey Module example)

In this tutorial you will create a web services method that will return the questions configured for the Survey module

1) Install IWeb module and the Survey module in the DotNetNuke website.

2) Place an instance of the Survey module on a page and create a Survey.
This will ensure that you have data to return in the web method you will create.

3) Open the DotNetNuke site in Visual Studio (or Visual Web Developer Express)

4) Under the IWEB folder, that is under the App_Code  folder right-click on the IWebMethods folder and select Add New Item...

5) Choose Class for the template and enter IWebSurvey.vb for the name

6) The file will be created

7) Copy and paste the following code in the file and save it:

Namespace DotNetNuke.Modules.IWeb

Public Class SurveyInfo
   ' local property declarations
   Public SurveyId As
Integer
   Public
ModuleId As
Integer
   Public
Question As
String
   Public
ViewOrder As
Integer
   Public
OptionType As
String
   Public
CreatedByUser As
Integer
   Public
CreatedDate As
Date
   Public
Votes As
Integer
End
Class

Partial Public Class WebService

" GetSurveys *DotNetNuke* |IWEB Core| #IWEB Misc# !Portal! "), SoapHeader("IWebCredentials")> _

Public Function GetSurveys() As List(Of SurveyInfo)
Dim SurveyInfolist As List(Of SurveyInfo) = New List(Of
SurveyInfo)
Dim objIWebAuthendication As New
IWebAuthendication(IWebCredentials)

If Not objIWebAuthendication.ValidAndAuthorized()
Then
   Dim SurveyInfo As SurveyInfo = New
SurveyInfo
   SurveyInfo.Question =
"Not Authorized"
   SurveyInfolist.Add(SurveyInfo)
   Return SurveyInfolist

End If

Dim mySqlString As String = ""
mySqlString =
"SELECT * FROM {databaseOwner}{objectQualifier}Surveys"
   Using dr As
IDataReader = _
      CType(DotNetNuke.Data.DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), Nothing), IDataReader)

      While
dr.Read
         Dim SurveyInfo As SurveyInfo = New
SurveyInfo
         SurveyInfo.SurveyId = Convert.ToInt32(dr(
"SurveyId"
))
         SurveyInfo.Question = Convert.ToString(dr(
"Question"
))
         SurveyInfo.OptionType = Convert.ToString(dr(
"OptionType"
))
         SurveyInfo.ViewOrder = Convert.ToInt32(ConvertNullInteger(dr(
"ViewOrder"
)))
         SurveyInfo.CreatedByUser = Convert.ToInt32(dr(
"CreatedByUser"
))
         SurveyInfo.CreatedDate = Convert.ToDateTime(dr(
"CreatedDate"
))
         SurveyInfolist.Add(SurveyInfo)
      End
While
End
Using
Return
SurveyInfolist
End
Function

Private
Shared Function ConvertNullInteger(ByVal Field As Object) As
Integer
   If
Field Is DBNull.Value
Then
      Return
0
   Else
      Return
Convert.ToInt32(Field)
   End
If
End
Function

End
Class

End Namespace

8) In the web browser, place an instance of the IWEB module on a page and configure it.
Then click on the link that appears after "This website implements this web service:"

9) The method will now appear in the list

Creating a IWEB Extension

Follow these steps to create a DotNetNuke module package that can be installed in a DotNetNuke portal that has the basic IWEB package installed.

Understanding the IWEB expansion model.

IWEB uses partial classes to allow you to create additional web services methods without replacing or re-installing IWEB.

In the App_Code/IWeb/IWebMethods folder,

all the class files are partial classes of the DotNetNuke.Modules.IWeb.WebService class.

All the class files will be compiled into a single DotNetNuke.Modules.IWeb.WebService class.

The methods will then be available through the /DesktopModules/IWeb/webservice.asmx file that is tied to that class.

When creating an additional IWEB method, you follow the steps in the tutorial above and package your new method in a DotNetNuke module package (see this tutorial on how to do that).

Putting the class file in the correct place

In order to work the class file containing your new web method must be placed in the App_Code/IWeb/IWebMethods folder. To do this you create an entry such as this in the .dnn file that is contained in your module package


[app_code]../IWeb/IWebMethods
IWebSurvey.vb

The ../IWeb/ in the path causes the file to be placed in the proper directory.

You can download the complete module (Survey Module Extension) from the Download Page.

    
Home  |  Screen Shots  |  Example Code  |  Installing  |  Download  |  Project
Copyright 2006-2009 by OpenLightGroup.net   |  Privacy Statement  |  Terms Of Use