InfoPath 2007 – solving XSN can not be used on server

With Microsoft Office SharePoint Server 2007 it is possible to use InfoPath forms to get feedback from users within a workflow A good starting point is the white paper – Walkthrough : Creating Office SharePoint Server 2007 workflows with Visual Studio but there are still some things you should really now before starting developing your own workflows on top of the SharePoint 2007 platform. This is the first of a series of postings about workflow in SharePoint 2007.

InfoPath 2007 is used in a couple of places in a SharePoint driven workflow:

When you want to develop a SharePoint workflow with Visual Studio 2005 you will first need to install the SharePoint workflow project templates. These Visual Studio project templates are installed when you install either the ECM Starter Kit (for Microsoft Office SharePoint Server ) or the Workflow Developer Starter Kit for Windows SharePoint Services 3.0.

When you start a new SharePoint workflow project, you will notice that the solution contains a number of files which are used to define the workflow solution – one of them is the workflow.xml file. In this file, you will need to specify the InfoPath forms you will be using by specifying the URNs. To find the URN of an InfoPath form, open the form in InfoPath in design mode and choose properties from the file menu.

<MetaData>

<Instantiation_FormURN>urn:schemas-microsoft-com:office:infopath:initform:-myXSD-2006-08-09T08-38-04</Instantiation_FormURN>

<Association_FormURN>urn:schemas-microsoft-com:office:infopath:initform:-myXSD-2006-08-09T08-38-04</Association_FormURN>

<Task0_FormURN>urn:schemas-microsoft-com:office:infopath:TaskEdit:-myXSD-2006-08-09T11-19-01</Task0_FormURN>

</MetaData>

Another location where you can find a reference to the InfoPath forms is in the feature.xml file – here you see the next section – make sure that you uncomment the <Property Key=”RegisterForms” Value=”*.xsn” /> line – this specifies that you will copy the InfoPath forms to the same directory as where you deploy the feature.xml file.

<Property Key=”GloballyAvailable” Value=”true” />

<Property Key=”RegisterForms” Value=”*.xsn” />

</Properties>

The last file that you need take a look at is install.bat – this will register your workflow solution, copy the necessary files and register the workflow assembly in the GAC.

Things you should watch out for:

  • Design the InfoPath files in a directory separate from your solution and publish them to the same directory (Use publish to network location) in which you have your workflow solution – this way you can simply use the <Property Key=”RegisterForms” Value=”*xsn” /> and use the default line in install.bat – xcopy /s /Y *.xsn “%programfiles%\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES\YourCustomFeature\”
  • Make sure that the Alternate access path is not filled in when publishing the InfoPath files – when publishing it to a network location, you should have received a warning – see screenshot listed below.


If something goes wrong, one of them the infamous “XSN can not be used on the server” error, you can troubleshoot the problem with the following steps:

  • Navigate to a command prompt
  • Navigate to this folder: %programfiles%\common files\microsoft shared\web server extensions\12\bin
  • Execute this command on each of your XSN files: stsadm.exe -o verifyformtemplate -filename <complete path to your xsn including the name.xsn>

This will give a more detailed description – if you are not sure if the access path is filled in for the InfoPath form you have deployed – you can rename the xsn file in the features directory to a CAB file and extract manifest.xsf from this file in this file – you should see that accessPath=”"

Leave a Comment

Sharepoint ebook

1. Essential SharePoint® 2007: Delivering High-Impact Collaboration

2. Pro SharePoint Solution Development: Combining .NET, SharePoint and Office 2007 (Expert’s Voice in Sharepoint)

3. Microsoft SharePoint: Building Office 2007 Solutions in C# 2005 (Expert’s Voice in Sharepoint)

4. Microsoft SharePoint Technologies: Planning, Design and Implementation (HP Technologies)

5. Essential sharepoint 2007, 2nd edition, Second edition

6. MOSS 2007 – The Complete Reference

7. Microsoft SharePoint 2007 Technologies: Planning, Design, and Implementation

8. Microsoft SharePoint 2007 Development Unleashed

9. Workflow in the 2007 Microsoft Office System

10. Microsoft SharePoint 2007 For Dummies

11. Microsoft® Windows® SharePoint® Services 3.0 Step by Step

12. Beginning SharePoint 2007 Administration: Windows SharePoint Services 3.0 and Microsoft Office SharePoint Server 2007

13. Beginning SharePoint 2007: Building Team Solutions with MOSS 2007

SharePoint Designer Tutorial

Essential SharePoint® 2007: Delivering High-Impact Collaboration

Essential SharePoint® 2007 focuses on utilizing Microsoft Office

SharePoint 2007 to improve collaboration and decision-making,

streamline processes, and solve real-world business problems.

Three leading SharePoint consultants systematically address the

crucial success factors, intangibles, and “gotchas” in SharePoint

deployment—showing exactly how to maximize business value and

reduce project risk.

Drawing on their unsurpassed experience, the authors walk you through

planning and architecting successful SharePoint solutions around the

unique needs of your business. Next, they address the operational support

and end-user functionality needed to make SharePoint 2007 work—with

special attention given to the organizational and political issues that can

make or break your project. Learn how to:

  • Define optimal, workable collaboration strategies
  • Build SharePoint applications people want to use
  • Architect SharePoint infrastructure for superior performance, reliability, and value. Provide your customers with state-of-the-art sites, blogs, and wikis
  • Use SharePoint content management to integrate documents, records, and Web content, and make it all searchable
  • Implement forms-based workflow to optimize virtually any business process
  • Quickly build business intelligence solutions using Web-base dashboards and server-based Excel Services
  • Organize and staff SharePoint support teams
  • Migrate efficiently from SharePoint 2003

Download:

Addison.Wesley.Essential.SharePoint.2007.Jun.2007.pdf

http://rapidshare.com/files/152577097/Addison.Wesley.Essential.SharePoint.2007.Jun.2007.pdf

Pro SharePoint Solution Development: Combining .NET, SharePoint and Office 2007 (Expert’s Voice in Sharepoint)

The landscape of doing SharePoint development has changed considerably in the last year, with the release of SharePoint Server 2007 and its related technologies. You need a contemporary reference to stay on top of the latest ways to combine .NET development techniques with your SharePoint development techniques, and SharePoint 2007 Development Techniques is your guide.

What makes this book unique are the topics that have never before been discussed in a SharePoint 2007 context. Learn how to incorporate the latest trends, capabilities, and enhancements in your daily SharePoint development activities.
What you’ll learn

  • Using Windows Workflow Foundation to create workflows in SharePoint Designer
  • Integrating business messaging with BizTalk Server 2006 into your SharePoint sites
  • Developing list item relationships via a feature
  • Creating and sharing database data by combining SharePoint with SQL Server 2005 Reporting Services
  • Constructing queries using SQL full-text extensions

Download:

Apress_2C.Pro.Sharepoint.2007.Development.Techniques.pdf

http://rapidshare.com/files/152577082/Apress_2C.Pro.Sharepoint.2007.Development.Techniques.pdf

Microsoft SharePoint: Building Office 2007 Solutions in C# 2005 (Expert’s Voice in Sharepoint)

Microsoft SharePoint: Building Office 2007 Solutions in C# 2005 is the third edition of Scot Hilliers market-leading SharePoint book. This book features extensive updates to the previous edition, with a complete focus on SharePoint 2007 and its integration with the 2007 Microsoft Office System. It also features new approaches for using SharePoint to improve business efficiency as well as new workflow solutions for SharePoint and BizTalk, plus a new chapter on building a SharePoint solution from start to finish. With this book, youll gain intermediate-level guidance for designing and deploying business solutions based on Microsoft SharePoint 2007 technologies. Hillier defines the business cases and scenarios for these technologies. He also reviews the installation, configuration, and administration of business solutions based on Microsoft SharePoint technologies, and provides programming instruction, guidance, and examples for custom web parts and solutions.

Download:

Apress.Microsoft.SharePoint.Building.Office.2007.Solutions.in.C.Sharp.2005.Feb.2007.pdf

http://rapidshare.com/files/152577128/Apress.Microsoft.SharePoint.Building.Office.2007.Solutions.in.C.Sharp.2005.Feb.2007.pdf

Microsoft SharePoint Technologies: Planning, Design and Implementation (HP Technologies)

“Microsoft SharePoint Technologies” provides an in-depth examination of the tasks involved in planning, designing and deploying the product in the enterprise: from the user’s perspective, the administrator’s perspective, and the application developer’s perspective. It looks at how readers can maximize their investment by integrating the SharePoint Portal Server with… More other enterprise applications in their environment.

Download:

Digital.Press.Microsoft.SharePoint.Technologies.Nov.2004.ebook-LinG.pdf

http://rapidshare.com/files/152577289/Digital.Press.Microsoft.SharePoint.Technologies.Nov.2004.ebook-LinG.pdf

Essential sharepoint 2007, 2nd edition, Second edition

Overview

If you’re considering the vastly improved 2007 version of SharePoint, this concise, practical and friendly guide will teach you how to get the most from the latest version of Microsoft’s information-sharing and collaboration platform. Essential SharePoint 2007 demonstrates how your business can use SharePoint to control documents, structure workflow, and share information over the Web using standard tools business users already know — Microsoft Office and Internet Explorer. Written in a conversational tone by internationally recognized SharePoint consultant and trainer Jeff Webb, this book helps SharePoint administrators, site owners, and power users quickly gain the skills necessary to perform a wide variety of tasks for intranet and extranet web sites, and explains what’s new in SharePoint 2007 for experienced SharePoint 2003 administrators. Essential SharePoint 2007 teaches you how to:

· Use SharePoint 2007 with Outlook, Word and Excel, and as a document management tool, replacing, for example, shared network drives with libraries

· Build and customize sites, lists, libraries and web parts for intranets and extranets

· Use SharePoint 2007 for team communication through blogs, wikis, surveys, and RSS and email alerts

· Build a SharePoint workflow application

· Create and program web parts in order to deliver custom services and data to a site

· Deploy and administer SharePoint 2007

Each chapter ends with a summary of best practices advocated by the author, and the first few chapters of the book are ideal as training materials for end users. Later chapters give developers and administrators tools not only to keep company sites running smoothly, but also to customize and extend them. The book also contains several appendices with a glossary of terms and hard-to-find information. Essential SharePoint 2007 is a one-stop task-oriented guide for learning what’s necessary to make this tool a vital part of team productivity.

Download:

Essential_20SharePoint_20_202nd_20Edition_20_20-_20O_27Reilly.pdf

http://rapidshare.com/files/152577291/Essential_20SharePoint_20_202nd_20Edition_20_20-_20O_27Reilly.pdf

MOSS 2007 – The Complete Reference

The definitive guide to Microsoft Office SharePoint Server 2007″This well-planned and well-written book offers a comprehensive reference for IT professionals, application developers and business analysts working with SharePoint applications.” –James A. Robertson, MCSD.NET, Senior Software Engineer, Applied Information SciencesDeploy and manage Microsoft Office SharePoint Server 2007 in the enterprise with help from this one-stop resource. Through detailed instructions, screenshots, and code samples, this comprehensive guide shows you, step-by-step, how to use SharePoint Server and make the most of all its powerful tools and utilities.Microsoft Office SharePoint Server 2007: The Complete Reference explains how to develop a customized installation plan, configure the server for optimal performance, and administer users, documents, and content. You’ll get full details on designing feature-rich portals and collaboration sites, creating user-friendly forms and workflows, using modular Web Parts, and incorporating business data. Install and configure SharePoint Server for the entire enterpriseManage the server from the Central Administration siteDesign SharePoint Server portals, websites, lists, and document librariesWork with SharePoint Web Parts or build your ownEnsure cross-site consistency using site columns and content typesCreate site definitions and templates using SharePoint Designer and Visual StudioBuild custom workflows using SharePoint Designer Extend SharePoint Server using the Object Model and Event ReceiversImport and map enterprise information using the Business Data CatalogUse the advanced services of Office Search and Excel Web Services

Download:

McGraw.Hill.Microsoft.Office.SharePoint.Server.2007.The.Complete.Reference.Sep.2007.007149328X.pdf

http://rapidshare.com/files/152577490/McGraw.Hill.Microsoft.Office.SharePoint.Server.2007.The.Complete.Reference.Sep.2007.007149328X.pdf

Microsoft SharePoint 2007 Technologies: Planning, Design, and Implementation

Microsoft SharePoint 2007 Technologies: Planning, Design and
Implementation provides an in-depth examination of the tasks involved in
planning, designing and deploying SharePoint in your enterprise.
SharePoint 2007 significantly extends the breadth of capabilities for
end users, administrators, developers, and designers. The cutting-edge
technology encompasses some major new functional areas such as Business
Intelligence, Information LifeCycle Management, and Enterprise Content
Managementall can be leveraged to satisfy many different business
scenarios. SharePoint 2007 Technologies will provide readers with
practical knowledge and techniques about integration of other 2007
products such as Office and Exchange Server, and readers will walk away
with the ability to easily expose and leverage back-end business data
and understand how it all joins together. Readers will further gain a
solid appreciation of the architecture, administration, end user
features, development, and integration opportunities offered by
SharePoint 2007. The expertise of the author team in helping many large
corporations deploy Microsoft technologies within their enterprises
makes this book an invaluable tool to businesses of any size.

Download:

Microsoft_20SharePoint_20_20Technologies_20-_20Digital_20Press.pdf

http://rapidshare.com/files/152577458/Microsoft_20SharePoint_20_20Technologies_20-_20Digital_20Press.pdf

Microsoft SharePoint 2007 Development Unleashed

This is the most comprehensive, practical guide to building enterpriseclass applications with SharePoint 2007, ASP.NET 2.0, Visual C# 2005, and the Microsoft Office 2007 system. Microsoft SharePoint 2007 Development Unleashed is designed for every working .NET developer: both those with SharePoint experience and those new to SharePoint. The authors thoroughly introduce SharePoint 2007 as a development platform and offer in-depth, example-rich coverage of every significant tool for programmers–from “Features and Solutions” to list events, from user profiles to Web Parts. You’ll walk step-by-step through building each major type of SharePoint application. You’ll also find in-depth coverage of SharePoint 2007’s rich collection of built-in Web services, including services for building document workspaces, centralizing the management of Excel spreadsheets, ensuring security, and much more.

Detailed information on how to…

  • Use CAML, SharePoint’s XML-based language for defining content, manipulating searches, and more
  • Work with the SharePoint Object Model
  • Build reusable packages for easy deployment to SharePoint server farms
  • Program SharePoint webs, sites, document libraries, and files
  • Leverage SharePoint 2007’s improved lists and new list events
  • Manipulate and query meetings and Meeting Workspaces
  • Integrate external business data into SharePoint applications
  • Construct business workflows for enterprise content management and other applications
  • Program ASP.NET-based SharePoint Web Parts, from the basics to state-of-the-art techniques
  • Create Web Parts that can provide and consume data through connections
  • Use SharePoint 2007’s built-in Web services for managing document and Meeting Workspaces, imaging, and lists
  • Centralize spreadsheet storage and management with Excel Services
  • Manage user profiles and enhance application security
  • Debug and deploy SharePoint 2007 applications
  • Work with Records Repositories and metadata

Download:

Sams.Microsoft.SharePoint.2007.Development.Unleashed.May.2007.pdf

http://rapidshare.com/files/152577541/Sams.Microsoft.SharePoint.2007.Development.Unleashed.May.2007.pdf

Workflow in the 2007 Microsoft Office System

Workflow is the glue that binds information worker processes, users, and artifacts. Without workflow, information workers are just islands of data and potential. Workflow in the 2007 Microsoft Office System details how to implement workflow in SharePoint 2007 and the rest of the 2007 Office System to help information workers share data, enforce processes and business rules, and work more efficiently together or solo.

This book covers anything you’re likely going to need to know — from what workflow is all about, to creating new Activities; from InfoPath forms to ASP.Net forms; from the Rules Engine to the object model. There’s even a section on integrating Office 2003 clients with SharePoint 2007 workflows. You’ll come away from reading this book with solid knowledge of how to implement workflow in the new world of Office and SharePoint.

Download:

WokrkflowInThe2007MicrosoftOfficeSystem.pdf

http://rapidshare.com/files/152577665/WokrkflowInThe2007MicrosoftOfficeSystem.pdf

Microsoft SharePoint 2007 For Dummies

Match SharePoint to your specific business needs
The fun and easy way to deploy SharePoint in your business today!
Are you stymied by SharePoint? This plain-English guide offers simple instructions and focused coverage of this powerful tool, giving you practical solutions to real-world SharePoint challenges. You’ll install SharePoint, create sites and grant access, manage data and business processes, use sites to improve employee relations and marketing, put interactive reports and forms on a portal, and much more!

  • Set up a SharePoint portal
  • Manage portal content and Office documents
  • Integrate Office 2007 with SharePoint
  • Use SharePoint to collaborate
  • Create personalized sites
  • Monitor and back up your portal

Download:

For.Dummies.Microsoft.SharePoint.2007.For.Dummies.Apr.2007.chm

http://rapidshare.com/files/152577350/For.Dummies.Microsoft.SharePoint.2007.For.Dummies.Apr.2007.chm

Microsoft® Windows® SharePoint® Services 3.0 Step by Step

The smart way to learn Microsoft Windows SharePoint Services 3.0—one step at a time!

Experience learning made easy—and quickly teach yourself how to use Windows SharePoint Services to enable effective team collaboration. With Step By Step, you set the pace—building and practicing the skills you need, just when you need them!

•Build your own SharePoint site with easy-to-use templates
•Create lists and libraries to store information
•Add discussion boards, wikis, and blogs
•Set up Document and Meeting Workspaces for easy collaboration
•Share calendars, contacts, and data from Microsoft Office programs
•Customize your pages with Web Parts

Your all-in-one learning experience includes:
•Files for building skills and practicing the book’s lessons
•Fully searchable eBook
•Windows Vista Product Guide eReference—plus other resources on CD

Download:

Microsoft.Press.Microsoft.Windows.SharePoint.Services.3.0.Step.by.Step.Apr.2007.chm

http://rapidshare.com/files/152577636/Microsoft.Press.Microsoft.Windows.SharePoint.Services.3.0.Step.by.Step.Apr.2007.chm

Beginning SharePoint 2007 Administration: Windows SharePoint Services 3.0 and Microsoft Office SharePoint Server 2007

With this practical guide, you’ll quickly learn how to build SharePoint 2007 sites that meet your business needs. SharePoint MVP (Microsoft Most Valuable Professional) Göran Husman walks you through everything from planning and installation to configuration and administration so you can begin developing a production environment. He also shows you how to take advantage of numerous SharePoint features that will dramatically enhance your sites.
You’ll find practical and easy-to-follow steps throughout this book that will enable you to customize templates for SharePoint, build your own Site Definition, and utilize SharePoint Designer. Typical scenarios and tasks that you’ll most likely encounter along the way are also presented, such as configuring an intranet, setting up document management, and managing projects. And you’ll discover how to use smart add-ons and utilities in order to improve navigation, integrate with other systems, design workflow solutions, and more.

Download:

Wrox.Beginning.SharePoint.2007.Administration.Jun.2007.chm

http://rapidshare.com/files/152577778/Wrox.Beginning.SharePoint.2007.Administration.Jun.2007.chm

Beginning SharePoint 2007: Building Team Solutions with MOSS 2007

Get ready to harness the power of SharePoint 2007 to build and customize your own collaborative sites. This informative guide uncovers all of SharePoint’s technical components and shows you how to effectively utilize them to meet specific business requirements. You’ll learn how to address critical information management problems as you gain the skills to become a SharePoint application champion.

Inside you’ll find detailed descriptions and illustrations that highlight SharePoint’s functionality along with realistic scenarios that demonstrate how to apply the information. You’ll first discover the latest features of SharePoint and its various technologies. You’ll then explore everything from commonly used items all the way to the most complex capabilities of the platform. This approach will give you the tools so you can quickly create and modify your own SharePoint site that drives more efficient business processes.

What you will learn from this book

  • How to use templates, themes, and master pages to design sites and workspaces
  • Steps for utilizing the new features of MOSS 2007
  • How to use workflows to efficiently manage a project
  • Tips for adding, modifying, importing and exporting Web Parts
  • Techniques for enhancing security by managing users with profiles and audiences
  • How to create business applications using forms
  • All about building and publishing web content from a single environment

Download:

Wrox.Beginning.SharePoint.2007.Building.Team.Solutions.with.MOSS.2007.Jun.2007.chm

http://rapidshare.com/files/152577869/Wrox.Beginning.SharePoint.2007.Building.Team.Solutions.with.MOSS.2007.Jun.2007.chm

SharePoint Designer Tutorial

SharePoint is a web-based collaboration and document management platform from Microsoft. Microsoft Office SharePoint Designer (SPD) is a WYSIWYG HTML editor and web design program, which has replaced FrontPage, and is the ideal environment for working with pages on a SharePoint site.

This book is ideal for people new to SharePoint Designer who need to put together a working SharePoint site as quickly as possible. If you who want to get started, and finished, as quickly as possible, this book is for you. You won’t just learn how to use SharePoint Designer; you’ll see how to use it to put together a SharePoint site.

This book will introduce you to the SharePoint Designer environment, and lead you through the key features as you complete important SharePoint customization activities. Throughout the book, you will be developing an example site for a wine business, and you will see what help SharePoint Designer offers, and step through clear instructions to get things done.

The book begins by familiarizing you with the Designer environment and helping you to connect to your SharePoint site. You will then learn how to add and format content, and use SharePoint’s workflow tools to collaborate with other content creators before learning how to connect to different SharePoint data sources.

You will also learn to use ASP.NET Web Parts in your SharePoint site to create calendars, graphs, integrate with Exchange Server, and add powerful search tools to your site.

Download:

SharePoint.Designer.Tutorial.pdf

http://rapidshare.com/files/152577599/SharePoint.Designer.Tutorial.pdf

Leave a Comment

Replicating a Tree table

Replicating a Tree table

source: http://www.maxdesign.com.au/presentation/tree-table/

Aim

The aim is to replicate a graphic table tree using HTML. This was based on a request from a Web Standards Group member. Posted here in case it is of use to someone else :)

Graphic example of a table tree

HTML example of a table tree

Name Location Color
House
Carrion Fly Worldwide gray
Office Fly California, Bay Area white
Common House Fly brown
Horse
Horn Fly Kansas red
Face Fly green
Stable Fly black

HTML code

<table summary="folder contents for fly types">
<thead>
<tr>
<th class="name">Name</th>
<th class="location">Location</th>
<th class="color">Color</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="3">House</th>
</tr>
<tr>
<th class="start">Carrion Fly</th>
<td>Worldwide</td>
<td>gray</td>
</tr>
<tr>
<th class="start">Office Fly</th>
<td>California, Bay Area</td>
<td>white</td>
</tr>
<tr>
<th class="end">Common House Fly</th>
<td></td>
<td>brown</td>
</tr>
<tr>
<th colspan="3">Horse</th>
</tr>
<tr>
<th class="start">Horn Fly</th>
<td>Kansas</td>
<td>red</td>
</tr>
<tr>
<th class="start">Face Fly</th>
<td></td>
<td>green</td>
</tr>
<tr class="end">
<th class="end">Stable Fly</th>
<td></td>
<td>black</td>
</tr>
</tbody>
</table>

CSS code

body
{
font-family: arial, helvetica, sans-serif;
}

table
{
border-collapse: collapse;
margin-bottom: 3em;
font-size: 70%;
line-height: 1.1;
}

tr:hover, td.start:hover, td.end:hover
{
background: #FF9;
}

th, td
{
padding: .3em .5em;
}

th
{
font-weight: normal;
text-align: left;
background: url(arrow.gif) no-repeat 2px 50%;
padding-left: 15px;
}

th.name { width: 12em; }
th.location { width: 12em; }
th.color { width: 10em; }

thead th
{
background: #c6ceda;
border-color: #fff #fff #888 #fff;
border-style: solid;
border-width: 1px 1px 2px 1px;
padding-left: .5em;
}

tbody th.start
{
background: url(dots.gif) 18px 54% no-repeat;
padding-left: 26px;
}

tbody th.end
{
background: url(dots2.gif) 18px 54% no-repeat;
padding-left: 26px;
}

Leave a Comment

Accessing ASP.NET Web Services with d…

Accessing ASP.NET Web Services with dojo.xhrGet

So I’ve been using the Dojo toolkit for a while now, but mainly for the Dijit and DojoX UI components. For the actual Ajax communication layer, I’ve been relying on the Microsoft Ajax framework because of it’s seamless integration with the ASP.NET Web Service model. Since I’ve got the whole mess of Dojo already being loaded into the browser, I figured I should drop the crutches, and work out how to work directly with the Dojo ajax framework.

The one downside of this is that you no longer get the client side proxies for your ASP.NET Web Services. Thus today’s article – how to directly access an ASP.NET JSON Web Service using dojo.xhrGet.

Part 1: Create a Web Service

This is pretty simple – just add a web service to your web site. I tend to put the code right in the asmx file, rather than in the code-behind in app_code, but that’s just personal preference.

<%@ WebService Language="C#" Class="ASPWebService" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ASPWebService  : System.Web.Services.WebService {

    [WebMethod]
 public string SayHello() {
 return "Hello to Dojo " + DateTime.Now.ToLongDateString();
 }
 }

By default your web service will be configured to “speak” SOAP, which is fine if you are consuming it from another application, but for Ajax based browser apps, it’s much easier to work with JSON.

Part 2: JSON-ify the Web Service

This is actually really simple – just include System.Web.Script.Services, and the [ScriptService] attribute to the web service as shown below.

<%@ WebService Language="C#" Class="ASPWebService" %>
using System;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class ASPWebService  : System.Web.Services.WebService {

    [WebMethod]
 [ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet=true)]
 public string SayHello() {
 return "Hello to Dojo " + DateTime.Now.ToLongDateString();
 }   }

We also add a [ScriptMethod] attribute to the WebMethod. We do this for two reasons – first, we want to specify that the response format should be JSON, and we also want to allow access to this method via http Get’s (this is disabled by default).

At this point you can hit the web service in your web browser, and get the standard Web Service browser. But if you also stick /js on the end of the url, you will get the client side Javascript that integrates with the MS Ajax Framework. But we’re trying to work with Dojo, so we’ll move on…

Part 3: Testing the Service in a Browser

Our simple “SayHello” web method does not take any arguments, so we should be able to just “GET” it via a browser.

The tricky bit that took me some time to sleuth down was that you also need to edit web.config to tell the web service to respond to all Gets and Posts. Add this section (just copy out the parts you are missing – do not paste this whole thing into your web.config or you will get an error!):

 <system.web>
 <webServices>
 <protocols>
 <add name="HttpGet"/>
 <add name="HttpPost"/>
 </protocols>
 </webServices>
</system.web>

Once you do this, you will get the response back. Despite the fact that we have used the [ScriptMethod] attribute to specify that the SayHello web method should return Json, this will only occur if you sent the request content-type to “application/json; charset=utf-8″. Without that, you’ll still get xml.

Part 4: Create a Simple Page

For this, I created about the simplest page I could – just a button and a div that will be updated. Here’s the whole page…

<!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>
 <title>Dojo to ASP.NET WebServices</title>
 <script type="text/javascript"
 src="http://o.aolcdn.com/dojo/1.1.1/dojo/dojo.xd.js"
 djConfig="parseOnLoad:true, isDebug:true">
</script>
 <script type="text/javascript">
 function updateSampleOne(){
 var contentNode = dojo.byId("sampleone");
 dojo.xhrGet({
 url: "./ASPWebService.asmx/SayHello",
 handleAs: "json",
 contentType: "application/json; charset=utf-8",
 load: function(data,args){contentNode.innerHTML = data.d;},
 error: function(error,args){console.warn("error!",error);}
 });
 };
 </script>
 </head>
<body>
<h1>Using Dojo to Consume ASP.NET JSON WebServices</h1>
<input id="btGetString" type="button"
 value="Update" onclick="updateSampleOne();" />
<div id="sampleone">This will update</div>
</body>
</html>

Breaking down the dojo code…

var contentNode = dojo.byId(“sampleone”);

This simply get’s a the div that we’ll be updating.

dojo.xhrGet({
 url: "./ASPWebService.asmx/SayHello",
 handleAs: "json",
 contentType: "application/json; charset=utf-8",
 load: function(data,args){contentNode.innerHTML = data.d;},
 error: function(error,args){console.warn("error!",error);}
});

This is the actual ajax xhr request. Since we are using a GET, we are using dojo.xhrGet.

The Url of our web service is the asmx file followed by the name of the web method. Since it’s located in the same folder as this html file, we reference it as ./ASPWebService.asmx/SayHello.

The response will be json, so we set handleAs to json

We set the contentType to “application/json; charset=utf-8″ as per the ASP.NET security requirements.

When the response returns, we need to do something with it, this is where load comes in. Dojo uses anonymous functions a lot, and for a simple situation like this, it’s pretty easy to follow. The returned JSON is:

{“d”:”Hello to Dojo Tuesday, June 03, 2008″}.

So we set the contentNode.innerHTML is set to data.d

Should an error occur, the error function is called.

Summary:

So – while this is a little more convoluted than just using the MS Ajax client library and the Script Manager, it does save us from loading multiple client-side frameworks. Since I’m using Dojo for many other UI components, it seemed a waste to also drag along MS Ajax when this is a viable alternative.

One may ask why use the ASP.NET Web Services model? Well, from the server side it’s pretty easy to work with. Once a service is created you can access it via Json or SOAP. They are also easy to unit test.

I’ll likely extend this with some more complex examples – like submitting a form, or sending / receiving complex types, but I’ll leave it here for now.

Download the sample code

Comments (3)

Exposing Web Services to Client Scrip…

Accessing ASP.NET Web Services with dojo.xhrGet

So I’ve been using the Dojo toolkit for a while now, but mainly for the Dijit and DojoX UI components.  For the actual Ajax communication layer,  I’ve been relying on the Microsoft Ajax framework because of it’s seamless integration with the ASP.NET Web Service model. Since I’ve got the whole mess of Dojo already being loaded into the browser, I figured I should drop the crutches, and work out how to work directly with the Dojo ajax framework.

The one downside of this is that you no longer get the client side proxies for your ASP.NET Web Services. Thus today’s article – how to directly access an ASP.NET JSON Web Service using dojo.xhrGet.

Part 1: Create a Web Service

This is pretty simple – just add a web service to your web site. I tend to put the code right in the asmx file, rather than in the code-behind in app_code, but that’s just personal preference.

<%@ WebService Language="C#" Class="ASPWebService" %>using System;using System.Web;using System.Web.Services;using System.Web.Services.Protocols;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class ASPWebService  : System.Web.Services.WebService {

    [WebMethod]
public string SayHello() {        
return "Hello to Dojo " + DateTime.Now.ToLongDateString();
}
}

By default your web service will be configured to “speak” SOAP, which is fine if you are consuming it from another application, but for Ajax based browser apps, it’s much easier to work with JSON.

Part 2: JSON-ify the Web Service

This is actually really simple – just include System.Web.Script.Services, and the [ScriptService] attribute to the web service as shown below.

<%@ WebService Language="C#" Class="ASPWebService" %>
using System;using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Script.Services;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ScriptService]
public class ASPWebService  : System.Web.Services.WebService {

    [WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json, UseHttpGet=true)]
public string SayHello() {        
return "Hello to Dojo " + DateTime.Now.ToLongDateString();
}
}

We also add a [ScriptMethod] attribute to the WebMethod. We do this for two reasons – first, we want to specify that the response  format should be JSON, and we also want to allow access to this method via http Get’s (this is disabled by default).

At this point you can hit the web service in your web browser, and get the standard Web Service browser. But if you also stick /js on the end of the url, you will get the client side Javascript that integrates with the MS Ajax Framework. But we’re trying to work with Dojo, so we’ll move on…

Part 3: Testing the Service in a Browser

Our simple “SayHello” web method does not take any arguments, so we should be able to just “GET” it via a browser.

The tricky bit that took me some time to sleuth down was that you also need to edit web.config to tell the web service to respond to all Gets and Posts. Add this section (just copy out the parts you are missing – do not paste this whole thing into your web.config or you will get an error!):

 <system.web>
 <webServices>
 <protocols>
 <add name="HttpGet"/>
 <add name="HttpPost"/>
 </protocols>
 </webServices>
</system.web>

Once you do this, you will get the response back. Despite the fact that we have used the [ScriptMethod] attribute to specify that the SayHello web method should return Json, this will only occur if you sent the request content-type to “application/json; charset=utf-8″. Without that, you’ll still get xml.

Part 4: Create a Simple Page

For this, I created about the simplest page I could – just a button and a div that will be updated. Here’s the whole page…

<!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>
<title>Dojo to ASP.NET WebServices</title>
<script type="text/javascript"
src="http://o.aolcdn.com/dojo/1.1.1/dojo/dojo.xd.js"         
djConfig="parseOnLoad:true, isDebug:true">
</script>
<script type="text/javascript">
function updateSampleOne(){
 var contentNode = dojo.byId("sampleone");
 dojo.xhrGet({
url: "./ASPWebService.asmx/SayHello",
 handleAs: "json",
contentType: "application/json; charset=utf-8",
load: function(data,args){contentNode.innerHTML = data.d;},
error: function(error,args){console.warn("error!",error);}
});    

};     </script>    <
/head>
<body>
<h1>Using Dojo to Consume ASP.NET JSON WebServices</h1>
<input id="btGetString" type="button" value="Update" onclick="updateSampleOne();" />
<div id="sampleone">This will update</div>
</body>
</html>

Breaking down the dojo code…

var contentNode = dojo.byId(“sampleone”);

This simply get’s a the div that we’ll be updating.

dojo.xhrGet({
url: "./ASPWebService.asmx/SayHello",
handleAs: "json",
contentType: "application/json; charset=utf-8",
load:
     function(data,args){contentNode.innerHTML = data.d;},
error: function(error,args){console.warn("error!",error);}});

This is the actual ajax xhr request. Since we are using a GET, we are using dojo.xhrGet.

The Url of our web service is the asmx file followed by the name of the web method. Since it’s located in the same folder as this html file, we reference it as ./ASPWebService.asmx/SayHello.

The response will be json, so we set handleAs to json

We set the contentType to “application/json; charset=utf-8″ as per the ASP.NET security requirements.

When the response returns, we need to do something with it, this is where load comes in. Dojo uses anonymous functions a lot, and for a simple situation like this, it’s pretty easy to follow. The returned JSON is:

{“d”:”Hello to Dojo Tuesday, June 03, 2008″}.

So we set the contentNode.innerHTML is set to data.d

Should an error occur, the error function is called.

Summary:

So – while this is a little more convoluted than just using the MS Ajax client library and the Script Manager, it does save us from loading multiple client-side frameworks. Since I’m using Dojo for many other UI components, it seemed a waste to also drag along MS Ajax when this is a viable alternative.

One may ask why use the ASP.NET Web Services model? Well, from the server side it’s pretty easy to work with. Once a service is created you can access it via Json or SOAP. They are also easy to unit test.

I’ll likely extend this with some more complex examples – like submitting a form, or sending / receiving complex types, but I’ll leave it here for now.

Download the sample code

Comments (1)

Older Posts »