Impersonated Searching against SharePoint

by Vishal 5. November 2013 08:59
Like many typical deployments of SharePoint 2010 and FAST Search Server for SharePoint 2010, I’ve been dealing with one recently that has a search center that uses Kerberos authentication.
Consider the following scenario where you have a client web application that uses the SharePoint (with FAST) search service to perform searches and publish the results to users.
User -----------> Client Web App ------------> SharePoint
In a typical intranet scenario, the user authenticates to the Client Web App using windows authentication. The client then needs to pass the user identity through to the backend SharePoint search service in order to provide the security trimmed results back to the user.
The out-of-the-box way to do this with SharePoint, is to set up the Kerberos authentication for the Client Web App and for the SharePoint search center by setting up SPNs for the domain identity that is used as the app pool running the client web app and delegation rights. That way, the user can authenticate to the client web app and the app pool identity can then delegate that Kerberos ticket back to SharePoint when calling the search service. This works but setting up Kerberos is tricky. The other disadvantage that I’ve seen is that this works great when the User’s browser is IE since IE supports NTLM authentication for the intranet by default. For other users that are on Linux systems or Macs or using browsers like Firefox and Chrome, NTLM authentication is tricky and requires browser specific configuration to make it work.
Fortunately there’s another way we can make this scenario work but it does require custom development. We can make SharePoint impersonate a user when performing a search using a trusted identity. Here your client web application will be running as the trusted domain identity that will be allowed to impersonate a user.
On the SharePoint side, we can create a solution, that deploys a web service that can perform an impersonated search on behalf of a user using the object model. The client application can then call this new service instead of the out of the box search.asmx.
Here is the code for the web service that will do impersonated searches:
    class SearchService
        private const string TRUSTED_ACCOUNT = @"\trustedserviceaccount";
        private const string SEARCH_SITECOLLECTION = "";

        public DataTable TrustedImpersonatedQuery(string UserName, string QueryText, string[] ReturnFields, SortProperty[] SortFields, int StartIndex, int PageSize)
            DataTable dt = null;
            string NTAccount = HttpContext.Current.User.Identity.Name.ToLower();
            if (NTAccount.Equals(TRUSTED_ACCOUNT)) //only do impersonation if the search is requested by the trusted account
                    using (WindowsIdentity impersonatedIdentity = new WindowsIdentity(UserName + ""))
                        using (WindowsImpersonationContext wic = impersonatedIdentity.Impersonate())
                            dt = Query(QueryText, ReturnFields, SortFields, StartIndex, PageSize);
            else //else do an unimpersonated search
                dt = Query(QueryText, ReturnFields, SortFields, StartIndex, PageSize);
            return dt;

        private DataTable Query(string QueryText, string[] ReturnFields, SortProperty[] SortFields, int StartIndex, int PageSize)
            DataTable dt = null;
            using (SPSite SearchSiteCollection = new SPSite(SEARCH_SITECOLLECTION))
                using (KeywordQuery kq = new KeywordQuery(SearchSiteCollection))
                    kq.ResultsProvider = SearchProvider.FASTSearch;
                    kq.EnableFQL = false;
                    foreach (SortProperty s in SortFields)
                        kq.SortList.Add(s.Name, (Microsoft.Office.Server.Search.Query.SortDirection)Enum.Parse(typeof(Microsoft.Office.Server.Search.Query.SortDirection), s.Direction.ToString()));
                    kq.RowLimit = PageSize;
                    kq.StartRow = StartIndex;
                    kq.QueryText = QueryText;
                    kq.ResultTypes |= ResultType.RelevantResults;
                    dt = kq.Execute()[ResultType.RelevantResults].Table;
                    dt.ExtendedProperties.Add("TotalResults", kq.QueryInfo.TotalResults);
            return dt;
    public enum SortDirection
    public class SortProperty
        public string Name;
        public SortDirection Direction;

Tags: , , , , , ,

.NET | ASP.Net | C# | MOSS | Sharepoint

Intranet, Portal, SharePoint, Wikis, Discussion Boards, File Shares & Content

by Vishal 6. May 2013 17:04

Common intranet content needs within an enterprise include:
1. Knowledge Sharing
2. CMS, Collaboration, Document Management and Publishing
3. Discussions
4. File storage

Outside of these broad needs, every enterprise will also have, both standard and custom, line of business applications like source control, bug tracking systems etc. As companies and content grow larger, related needs like social networking & collaboration and a solid enterprise search platform to effectively search, tie and share information across these platforms also becomes essential.

As many know, I’m a big fan of SharePoint. But It’s important to understand the problem SharePoint currently solves for an enterprise. A strategy that’s built on the premise that SharePoint is the solution for all of the above needs is a failing SharePoint strategy. Sooner or later your users will tell you that- because they’ve either used or seen other platforms that were more natural to use and/or addressed the specific area better.

Common platforms that many companies use to address the common intranet needs include some or a combination of:
1. SharePoint
2. Wiki platforms like Confluence, MediaWiki or others
3. Discussion Board platforms
4. File Shares
5. Other extendible CMS platforms like Drupal
6. Custom developed solutions

I’m going to leave out 5 and 6. I’m leaving out other extendible CMS solutions because, honestly, I like SharePoint and I do believe that it solves the same use-cases for an intranet. I’m leaving out Custom developed solutions as well because I’m a developer and custom developed solutions will solve your every need but are not always practical to implement, scale, enhance and maintain.

So let’s take a look at what’s left. I want to highlight the areas of strength for each platform, where they succeed and where they might fail.





File Shares

Need Addressed

Knowledge Sharing

CMS/ Collaboration/ Document Management/ Publishing


document storage, file (non-document) storage, archival 


·         Users create pages

·         Owner/users define:

o   Page content

o   Embed:

§  Images

§  links

o   Link to secure or structured content e.g.:

§  Files in source control

§  Documents in SharePoint

§  Bugs in bug tracker

·         Users create websites

·         Owner/ users define:

o   Site Data Sources (Lists & Document Libraries)

o   Site Pages

o   Site Content Permissions

o   Site Page Views (WebParts on a page that display data from a data source)

o   Site Structure

o   Embed:

§  Office documents

§  Web parts

§  External secure and unsecure data (reports, LOB data, bug tracking system…)

o   Link to Unstructured or public content:

§  Pages in Wiki

§  Internet sites 

·         Users Discuss

·         Owners/ Users define: 

o   Discussion Topics

o   permissions

o   Embed

§  Images

o   Link to secure or unsecure, structured or unstructured content

§  SharePoint

§  Wiki

§  Bugs from tracker

§  LOB Systems


·         Stores files

·         Owners/ Users:

o   Dump files

o   Manage permissions


Designed to

·         Used to Jot down an idea quickly – move details to the next page

·         Designed not to get in the way

o   Open permission set allows submission by everyone

o   Text based entry using wiki text

·         Used to Collaborate through content and process

o   Office integration

o   workflows

·         Designed to create structure

o   Granular permissions to lock down anything from complete sites to a specific document

o   Structured Lists to hold metadata around structured content in addition to the content

o   Structured document libraries to hold metadata around documents

o   Web Parts - Create different views of Lists and Document Libraries to present the content in a different form that it was created in

·         Used for open or closed discussions

·         Designed for quick

o   searching,

o   posting,

o   commenting,

o   linking


·         Used to store files that have no business metadata associated with them

·         The moment a document has business metadata around it – it should go to SharePoint.

·         Does not do versioning – SharePoint/ Perforce does

·         E.g.

o   Store the Windows 7 installer in a file share.

o   Store versioned application source code in perforce.

o   Store the versioned requirements document with related metadata such as the project, author, department in SharePoint.

o   Designed for quick storage/ retrieval of files


·         Full text searching for information

·         Full text searching as well as metadata searching

·         Full text searching 

Full text and file system metadata searching 


·         Is the place for structured content

·         Provides granular permissions

·         Is the place to store/ embed files

·         Is the place for unstructured content

·         Does not require site level management

·         Wiki capability provided inbuilt matches that of an enterprise wiki platform

·         Forums capability provided inbuilt matches that of a forums platform

·         Is an online file share

·         Integrates with existing LOB systems without custom development.


·         Can be replaced by SharePoint document libraries






The bottom line is that Collaborating, CMS, Knowledge Sharing, Discussions and file storage go hand in hand within the enterprise. The real challenge is how you provide a seamless experience & integration between the platforms.

The portal solution in this mix seems to be SharePoint. But it should allow its users to seamlessly transition to a wiki for authoring knowledge bases or forums for discussions. A sucessful strategy would Create interfaces between SharePoint, Wiki, Discussions as well, that allow content in each system to be shared, embedded and surfaced in other systems securely.

tags: SharePoint vs Wikis vs Drupal vs Forums for Intranet Portal

Tags: , , , , , ,

MOSS | Sharepoint

Removing Sharepoint Top and Left Navigation Using URL Query String Parameter

by Vishal 22. July 2011 11:52

Sometimes you may need to be able to display a page in MOSS with the left nav and top nav that is part of the default master page and layout. One of the reasons could be that you're trying to display the page within the frame of another application and only wish to show the page content.

In such a case here's a nifty way to hide the sharepoint 2007 navigational elements on a page without having to touch the masterpage or page layouts.

I crafted a custom webpart (attached) - dwp webpart without any server side code - that you can add to the webpart gallery of your site collection. The webpart is just a modified content editor webpart exported that puts a small ammount of javascript on the page to hide the navigation panes. It looks for a query string parameter called pure which if set to 1 will not display the navigation.

e.g. if the webpart is added to /default.aspx page on a site - if /default.aspx is called, the page will display as normal. If /default.aspx?pure=1 is called, the page will be displayed without any top nav or left nav.

ofcourse you can modify the script within the webpart any which way to only hide the left nav or only hide the top nav or hide custom elements as well with additional URL parameters.

this is the script that gets added to your page:

displaytype = JSRequest.QueryString["pure"];
document.write("<style>.ms-leftareacell,.ms-globallinks,.ms-siteaction,.ms-areaseparatorleft,.ms-rightareacell,.ms-areaseparatorright,.ms-areaseparatorcorner,.ms-titlearealeft,.ms-titlearearight,.ms-searchform,.ms-banner,.ms-buttonheightwidth,.ms-buttonheightwidth2, .ms-globalTitleArea, .ms-globalbreadcrumb, .ms-bannerContainer, .ms-pagetitleareaframe, .ms-consolestatuscell, .ms-pagemargin, .ms-bodyareapagemargin, .ms-pagebottommarginleft,.ms-pagebottommarginright, .ms-pagebottommargin, .ms-titleareaframe {display:none !IMPORTANT; } .ms-bodyareaframe, .ms-bodyareacell, .ms-propertysheet { border:0px !IMPORTANT; }</style>");

Quite simple really but effective. Enjoy.

NavigationHider.dwp (2.16 kb)


Project Server 2007 - Queue Job "WSS Workspace Create" in Processing state & taking a long time

by Vishal 17. February 2011 06:11

To add to my list of frustrations with MSPS 2007 -

  1. I created a new project
  2. I saved It
  3. I published it
  4. I checked it in
  5. I went into PWA - Project Center - Hit the edit project properties button - I got a message box saying "This Project is currently checked out. No edits can be made to it while it is checked out."
  6. I checked in Project Center and sure enough - the project shows checked out to me - but I checked it in!
  7. I reopened the project from Project professional and re-checked in.
  8. I went back to project center - still shows checked out to me!
  9. @!#%^$@!#%^

The answer was in the server settings - Enterprise Object Checkin. When I went to that list, I could see the project as being checked out to me with the state "Processing". This told me something about my checkin was still hed up. I went into Queue Management and it had the task "WSS Workspace Create" in "Processing" at 0 % and my checkin task was in the queue right after, held up by the "WSS Workspace Create" task.

Aparently, the first time I publish a project and check it in with the option set to create a workspace - the "WSS Workspace Create" gets created and takes a long time holding up the task queue for other tasks.

I have no idea what it is doing, why its taking that long and why it should hold up project check in. I just know that it does. To raise frustrations, I can already visit the project workspace site so I know its already created and available!!

I don't see anything in the ULS logs either hat may indicate foul behavior.

Is this normal? Does anyone face the same behavior in their production environments? Do you have any other insight on this? I'd love to hear about it.




After banging my head over this issue for a couple of days, I finally resolved it. The issue was due to 2 problems with the environment. I'll list them below.

1. A feature enabled of the base template for project workspace sites was not installed completely on one of the web servers in the farm. The result was that during the creation of the workspace site, because of a missing file in the features folder, sometimes the workspace could not get created and led to an error crreating workspace email being sent to the project owner and a failed entry in the server queue.

2. In our security security template for team members, every team member had been given access to project workspaces in the category "My Organization". Since this category contained all of the projects in the enterprise, this basically meant that all users needed to have access to all of the project workspaces created in the enterprise. Well guess what would happen whenever a project workspace had to be created? the Queue job to create the workspace and sync user permissions from the security group to the workspace site had to add every single person in the team member group - which is basically the entire enterprise (in my case 8000 people!) No wonder the job needed some time to complete the first time a project workspace was provisioned.

We fixed the corrupt feature and modified our security templates. this fixed the issues we were having. The project workspace almost gets provisoned instantly - there are no failures and queue jobs are not failing on saving or publishing projects.

hope this helps somebody!

Tags: , , , ,

Project Server 2007

Things I'm discovering about Project Server 2007

by Vishal 30. September 2010 05:46

If people have faced any of these, please feel free to comment, post work arrounds, rant. I'll add more as time goes on

  1. There are issues with the sync job that sync group/user permissions with WSS project workspace site permissions that cause the queue job to sometimes not finish. WHen taht happens, certain users get locked out of accessing PWA. the only cure I've found is to open and resave the user/group and when the new queue job finishes, the users access is restored.
  2. There is no way to allow a user to select from a list of saved workspace templates when publishing their project. Only one default template is allowed per PWA site instance
  3. no documented way of migrating projects from one instance to another

Tags: , , ,

Sharepoint | Project Server 2007

Configuration Specific Web.Config in Visual Studio 2010

by Vishal 30. July 2010 05:03

A cool feature of Visual Studio 2010 is the ability to have configuration files that are build configuration specific. Handling build configuration specific config files was always a challenge in the past where one had to store multiple config files for a dev environment versus a staging environment versus a production environment.

For example, a dev environment specific conf file would store the connection string to your dev database and the production envirnment web.config would store the connection string to your production database. Now when you moved your code between environments, you would have to make sure that the correct config file is copied over and that your production environment code is not accidentally pointing to your dev database.

This problem is solved by visual studio 2010 that allows cbuild configuration specific config files. In VS 2010, whenever you create a new web application project now, you'll see that your web.config in your solution explorer actually appears as an expandable node. When you expand it, you will see multiple configuration files for each of your build configurations, that can hold different values for each configuration.

Now when you build your application in a specific build configuration, the correct web.config settings get applied. Similarly when you publish, the correct web.config settings get published.

Tags: , , ,

ASP.Net | VseWss 3.0 v1.3

Multi-Tasking and Windows Mobile 7 - Myths & Reality

by Vishal 15. March 2010 11:59

So there was a lot of chatter online on whether the windows mobile 7 platform, soon to be released will support multi-tasking. The answer is yes and no.

Multi-tasking is a feature by virtue of which multiple applications can run on the device simultaneously sharing the platform compueting and other resources. For example, a user may wish to load a webpage in the browser application, while they read their email in the mail application.

The answer to whether the OS supports multi-tasking, is yes - in that it does natively support running multiple applications simultaneously. This will be seen out of the box for applications that ship with the phones. For example you will be able to use your mail application while a webpage is loading in the browser or be able to listen to music or watch videos, while browsing the web.

However, Microsoft is being careful about how the multitasking features are exposed for third party applications that don't ship out of the box with the phone. This is necessary for a number of reasons. If a platform allows all 3rd party code to run in the background, the users may face degraded performance of the app in the foreground, depending on what resources are being hogged by the application that is running in the background. Also badly written applications can cause wasteful usage of the platform resources in the background thereby causing unpredictable battery life performance etc.

The platform does allow the running 3rd party applications a grace period after the user has switched away from the application, during which the application may save state, handle closing events and do some background operations before it is shut down. All written applications will be able to hook onto this event. The platform also allows push notifications to be sent for applications to their users. The users will see these notifications, even if they are not using the applications and can then go into the applications to do more.

Another feature that is exposed to 3rd party applications is that they recieve notifications of system events such as for example a call coming in while the application is being used. Because of this, the users can switch away from the application, take the phone call and then return to the application and continue using it in the state that they left it.

Periodically update webpage with server data - Simulate pushing data from server to client

by Vishal 2. February 2010 04:23

JavaScript has a function, setInterval(code, timeout) that can be used to periodically update a visitors web browser. Using this feature you could simulate pushing updates from the server side to the clients browser using AJAX.

The setInterval(<code>, <timeout>) function call takes 2 parameters. <code> which is the javascript call to run and <timeout> is the interval at which to periodically make that call. The call specified as the <code> parameter can be an AJAX call to fetch the data and update the browser part.

function pageLoad(sender, args) { 
   setInterval('UpdatePage();', 2000); 

For example, the above  javascript function can be set to run on page load, which in turn will call the UpdatePage() Javascript call every 20 seconds.

for a complete example, take a look at the 4 guys site @

Tags: , , ,

.NET | Ajax | ASP.Net | JavaScript

Call a webservice from TSQL (Stored Procedure) using MSXML

by Vishal 22. December 2009 10:13

I am working on a n integration project that required me to call a webservice through a stored procedure in the SQL database. After proving my concept using the CLR integration features in Sql Server, I learned that the production database was actually running on Sql Server 2000 compatibility level. There went my proof of concept.


So now I have to resort to doing web service calls the old way, making post requests using MSXML. This is what my stored procedure looks like. 

CREATE proc [dbo].[spHTTPRequest] 
      @URI varchar(2000) = '',      
      @methodName varchar(50) = '', 
      @requestBody varchar(8000) = '', 
      @SoapAction varchar(255), 
      @UserName nvarchar(100), -- Domain\UserName or UserName 
      @Password nvarchar(100), 
      @responseText varchar(8000) output 
IF    @methodName = '' 
      select FailPoint = 'Method Name must be set' 
set   @responseText = 'FAILED' 
DECLARE @objectID int 
DECLARE @hResult int 
DECLARE @source varchar(255), @desc varchar(255) 
EXEC @hResult = sp_OACreate 'MSXML2.ServerXMLHTTP', @objectID OUT 
IF @hResult <> 0 
      EXEC sp_OAGetErrorInfo @objectID, @source OUT, @desc OUT 
      SELECT      hResult = convert(varbinary(4), @hResult), 
                  source = @source, 
                  description = @desc, 
                  FailPoint = 'Create failed', 
                  MedthodName = @methodName 
      goto destroy 
-- open the destination URI with Specified method 
EXEC @hResult = sp_OAMethod @objectID, 'open', null, @methodName, @URI, 'false', @UserName, @Password 
IF @hResult <> 0 
      EXEC sp_OAGetErrorInfo @objectID, @source OUT, @desc OUT 
      SELECT      hResult = convert(varbinary(4), @hResult), 
            source = @source, 
            description = @desc, 
            FailPoint = 'Open failed', 
            MedthodName = @methodName 
      goto destroy 
-- set request headers 
EXEC @hResult = sp_OAMethod @objectID, 'setRequestHeader', null, 'Content-Type', 'text/xml;charset=UTF-8' 
IF @hResult <> 0 
      EXEC sp_OAGetErrorInfo @objectID, @source OUT, @desc OUT 
      SELECT      hResult = convert(varbinary(4), @hResult), 
            source = @source, 
            description = @desc, 
            FailPoint = 'SetRequestHeader failed', 
            MedthodName = @methodName 
      goto destroy 
-- set soap action 
EXEC @hResult = sp_OAMethod @objectID, 'setRequestHeader', null, 'SOAPAction', @SoapAction 
IF @hResult <> 0 
      EXEC sp_OAGetErrorInfo @objectID, @source OUT, @desc OUT 
      SELECT      hResult = convert(varbinary(4), @hResult), 
            source = @source, 
            description = @desc, 
            FailPoint = 'SetRequestHeader failed', 
            MedthodName = @methodName 
      goto destroy 
declare @len int 
set @len = len(@requestBody) 
EXEC @hResult = sp_OAMethod @objectID, 'setRequestHeader', null, 'Content-Length', @len 
IF @hResult <> 0 
      EXEC sp_OAGetErrorInfo @objectID, @source OUT, @desc OUT 
      SELECT      hResult = convert(varbinary(4), @hResult), 
            source = @source, 
            description = @desc, 
            FailPoint = 'SetRequestHeader failed', 
            MedthodName = @methodName 
      goto destroy 
-- if you have headers in a table called RequestHeader you can go through them with this 
DECLARE @HeaderKey varchar(500), @HeaderValue varchar(500) 
      SELECT      HeaderKey, HeaderValue 
      FROM RequestHeaders 
      WHERE       Method = @methodName 
OPEN RequestHeader 
FETCH NEXT FROM RequestHeader 
INTO @HeaderKey, @HeaderValue 
      --select @HeaderKey, @HeaderValue, @methodName 
      EXEC @hResult = sp_OAMethod @objectID, 'setRequestHeader', null, @HeaderKey, @HeaderValue 
      IF @hResult <> 0 
            EXEC sp_OAGetErrorInfo @objectID, @source OUT, @desc OUT 
            SELECT      hResult = convert(varbinary(4), @hResult), 
                  source = @source, 
                  description = @desc, 
                  FailPoint = 'SetRequestHeader failed', 
                  MedthodName = @methodName 
            goto destroy 
      FETCH NEXT FROM RequestHeader 
      INTO @HeaderKey, @HeaderValue 
CLOSE RequestHeader 
DEALLOCATE RequestHeader 
-- send the request 
EXEC @hResult = sp_OAMethod @objectID, 'send', null, @requestBody 
IF    @hResult <> 0 
      EXEC sp_OAGetErrorInfo @objectID, @source OUT, @desc OUT 
      SELECT      hResult = convert(varbinary(4), @hResult), 
            source = @source, 
            description = @desc, 
            FailPoint = 'Send failed', 
            MedthodName = @methodName 
      goto destroy 
declare @statusText varchar(1000), @status varchar(1000) 
-- Get status text 
exec sp_OAGetProperty @objectID, 'StatusText', @statusText out 
exec sp_OAGetProperty @objectID, 'Status', @status out 
select @status, @statusText, @methodName 
-- Get response text 
exec sp_OAGetProperty @objectID, 'responseText', @responseText out 
IF @hResult <> 0 
      EXEC sp_OAGetErrorInfo @objectID, @source OUT, @desc OUT 
      SELECT      hResult = convert(varbinary(4), @hResult), 
            source = @source, 
            description = @desc, 
            FailPoint = 'ResponseText failed', 
            MedthodName = @methodName 
      goto destroy 
      exec sp_OADestroy @objectID 



The stored procedure takes the following parameters:

  1.  @URI: the URI of the web service
  2.  @MethodName: this would be ‘GET’ or ‘POST’
  3.  @RequestBody: this is your SOAP xml that you want to send
  4. @SoapAction: this the operation that you want to call on your service
  5. @UserName: NT UserName if your web service requires authentication
  6. @Password: the password if using NT Authentication on the web service
  7. @ResponseText: this is an out parameter that contains the response from the web service


Here is a sample call to my service 

declare @xmlOut varchar(8000)
Declare @RequestText as varchar(8000);
set @RequestText=
'<soapenv:Envelope xmlns:soapenv="" xmlns:tem="">
exec spHTTPRequest 
'', '', @xmlOut out
select @xmlOut 

The stored procedure runs and selects the response from my service call which in my case is:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="" xmlns:xsi="" xmlns:xsd="">
  <CreateOrderForMeResponse xmlns="">
    <Message>Order Created for me</Message>

Note that the stored procedure automatically adds the appropriate http headers for Content-Type, SoapAction and Content-Length. If you need to pass additional http headers with your request, refer the section in the center of the stored procedure which is commented out. Basically you need a table in your database called RequestHeaders with 3 columns; HeaderKey, HeaderValue, Method. Populate this table with the keys and values for the additional headers. The Method column will contain GET or POST depending on what method you are using.

Another thing to note here is that I tried the above calls with MSXML2.XMLHTTP and Microsoft.XMLHTTP but did not succeed with either. I kept getting an error from msxml3.dll or msxml6.dll with message "The parameter is incorrect". I believe this to be a bug with msxml that requires the request body text to be in a specific format that is not available through a sql data type and hence cannot be used via TSQL. THese will hoever work fine when performing a simple http request (non- SOAP) or a SOAP request that does not need a request body. for performing SOAP requests from within TSQL the only component that worked for me was MSXML2.ServerXMLHTTP. There are some third-party components that I came across, some paid, but MSXML2.ServerXMLHTTP worked just fine for me.

The next step is to actually take the SOAP response that I recieved and extract the appropriate data from it - that will be another post.

Tags: , , ,

.NET | C# | SQL | SQL Server Management Studio

Passing JavaScript Objects to the CLR

by Vishal 16. December 2009 08:19

Passing JavaScript Objects to the CLR

Asp.Net 3.5 makes it easy to pass JavaScript Objects to the CLR for AJAX calls. Here it is...

For this example, I created an ASP.Net Web Service Application which gave me a simple web service to start off with called Service1.asmx. The sample service has a single sample web method called HelloWorld() which just returns the text “Hello World”. For this example, since we want to pass something to the service method, I modify the service method a little bit so it looks like below:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Services; 
namespace JSAjaxTest 
    /// <summary> 
    /// Summary description for Service1 
    /// </summary> 
    [WebService(Namespace = "")] 
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] 
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    public class Service1 : System.Web.Services.WebService 
        public string HelloWorld(string text) 
            return text; 

 Basically I just modified the method to accept a string and return that same string back.

Now add an application page to the project, default.aspx, which will contain the javascript that makes the AJAX call. The default.aspx page contains a script manager, a html button and a piece of javascript that gets called when the button is clicked to make the AJAX call. This is what the page looks like:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="default.aspx.cs" Inherits="JSAjaxTest._default" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">


<html xmlns="" >

<head runat="server">


    <script type="text/javascript">

        function CallService() {

            JSAjaxTest.Service1.HelloWorld("Hello World", function(response) { alert(response); });





    <form id="form1" runat="server">


        &nbsp;<asp:ScriptManager ID="ScriptManager1" runat="server">


                <asp:ServiceReference Path="/Service1.asmx" />



        <input type="submit" value="hitme" onclick="javascript:CallService();" /></div>





Looking at the javascript on the page, the call is really made here:

JSAjaxTest.Service1.HelloWorld("Hello World", function(response) { alert(response); });

The call to the webservice through javascript uses the script manager to make the call, pass in the javascript argument and specifies the inline call back function which gets called when the AJAX call is complete. The inline function simply has an alert statement that displays the response.

When you run the project, clicking on the button will pass the text, “Hello World” to the “HelloWorld()” method of the web service via AJAX. There is no postback.

Tags: ,

.NET | C#

L symphonique de la derniere chanson, jh cherche professeur de danse, est tres belle et la partition se maintient au meme niv imitation replique rolex montres montre pendant toute la chanson, rehaussee par le son des violons. Un technicien et d ax pompes fnebes Bonio ces gandes tentes tiisees po assombi es maisons et signifie e dei. Mes dip seont es ps ties en es int ma magie po c de noveax replica uhren tos. replique montre diesele oU i fat veie a ce qe chaqe escapin soit mis en vae dans e moinde detai. "Je n'ai pas d'avis medical sur ta situation, mais par contre il est clair que tu en souffres, donc rien replique montres que pour a ton medecin devrait t'ecouter. Et "la" rando : les gorges de Samarie (mais attention, hyper frequente en ete). Le groupe etait assez heterogene, de la quinqua qui le faisait pour son plaisir aux etudiants bac +1 divers mais avec une majorite de terminales (toutes rolex replique sections confondues) donc je ne pense vraiment pas qu'il y ait eu de selection. D'autant qu'il y a deux nivcopie de montre rolex de difficulte et que certains chapitres ne seront accessibles qu'en ayant un minimum d'allies dans replique montre notre equipe, a la fin du copie de montre de luxe. Le fis d gitaiste des Pink Foyd fait appe de sa peine de pisonAge de 21 ans, e jene homme, etdiant en histoie a Cambidge, avait ete aete a son domicie apes a manifestation conte a rolex montre pas cher hasse des fais nivesitaies e 9 decembe a Londes, maqee pa des incidents.
Repliques Montres haute qualite vous aider a economiser beaucoup tout en appreciant la valeur du nom de marque. Vous voulez avoir cette montre luxe haut de gamme suisses sur votre main, mais replica uhren l'achat d'une voiture semble une meilleure option. Oui, c'est la realite. Ces montres symbole de statut social co?tent quelque chose replicas de relojes qui est au-dela pour permettre pour une personne normale. Mais ne desesperez hublot replique montres pas si vous ne pouvez pas vous permettre d'acheter ces montres de luxe. Vous avez une belle occasion d'acheter des montres de prestige nom Replique de la marque. Certaines personnes aiment l'aspect d'un veritable montres au poignet, ou replique rolex montres voulez juste nombreuses montres de marque pour correspondre a leur habillement, mais evitez patek philippe replica orologi de depenser des milliers de dollars que une vraie montre mai cots, ils se tournent vers les replique montre montres bonne replique. Si vous ne voulez pas acheter des montres de veritables montres de haute qualite puis de replicas sont votre choix ideal.