Calling web services from JavaScript in BBIS

Create your web service (asmx) and put it in the NetCommunity\WebServices folder.

MyCustomWebService.asmx

Imports System.Web.Services
Imports System.ComponentModel
Imports System.Web.Script.Services

<System.Web.Script.Services.ScriptService()>
<System.Web.Services.WebService(Namespace:="http://blackbaud.com/webservices/")>
<System.Web.Services.WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)>
<ToolboxItem(False)>
Public Class MyCustomWebService
    Inherits System.Web.Services.WebService

    <WebMethod()>
    Public Function GetText(ByVal name As String) As String
        name = HttpUtility.UrlDecode(name)

        Return "Hello " + name
    End Function
End Class

No you can call this method in your web service from your JavaScript like below.

function callGetText(name) {
    var params = {};
    params.name = encodeURIComponent(name);

    callWebMethod("GetText", params);
}

function callWebMethod(webmethod, params) {
    function onFail(jqXHR, textStatus, errorThrown) {
        alert("Error");
    }

    function onSuccess(data, textStatus, jqXHR) {
        alert(data.d);
    }

    BLACKBAUD.netcommunity.CallWebServiceMethod("MyCustomWebService", webmethod, onSuccess, onFail, JSON.stringify(params));
}

Now you can just call GetText(“Chris”) and it will then alert you, “Hey Chris”.

Happy Coding. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s