Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Call web service in asynchronous fashion inside a sharepoint webpa

4 views
Skip to first unread message

Pat

unread,
Sep 24, 2009, 2:47:22 PM9/24/09
to
I have a sharepoint webpart equipped with ajax feature. Inside the webpart,
there is a user control. Inside the user control, there are asynchronous
calls to a web service. In a normal ASP.NET application, the condition for
making async web service call is to add async="true" to the web page
directive. However, sharepoint's SPPageParserFilter class blocks some page
directive attributes, including the attribute async. So, if your webpart
makes async web serive call, a parser error occurs: “The async attribute on
the page directive is not allowed in this page”. People sugggest to use
client script (Miscrosoft's ajax javascript library or jquery) to contact the
web services. It means that there are a lot of javascript code, which I am
quite hesitated to handle. Just wonder whether you have solution for this
issue. The more details solution, the better. Thanks.
--
Pat

Chris Givens

unread,
Oct 5, 2009, 10:18:32 PM10/5/09
to
You can try to use the code examples in my 50064 web parts module with the
async lab:

http://cbt.architectingconnectedsystems.com/50064/50064%20_Module_13.htm

Hope it helps
Chris

"Pat" <Pa...@newsgroups.nospam> wrote in message
news:EDC8AC28-1AB6-49E5...@microsoft.com...

Pat

unread,
Oct 6, 2009, 1:35:01 PM10/6/09
to
Hi Chris,

Thanks a lot for your suggestion. I will try to use your way to handle it
and see whether it succeeds or not. Before doing that, I will show you what I
did before. I used web service proxy instead of Page.RegisterAsyncTask, which
was used by you. Here is the details showing you what I did:

1. My user control (which is enclosed by Ajax's UpdatePanel) uses web
service proxy, which has a method called GetEmployeeIDAsync and an event
named GetEmployeeIDCompleted. In the user control project, I added a Web
Reference and called as PatWS. The code-behind for this user control has
these codes:

private PatWS.PatWebService WS = new PatWS.PatWebService();

override protected void OnInit(EventArgs e)
{
base.OnInit(e);
WS.GetEmployeeIDCompleted += new GetEmployeeIDCompletedEventHandler
(OnGetEmployeeIDCompletedCompleted);
}

protected void Page_Load(object sender, EventArgs e)
{
if (!this.Page.IsPostBack)
{
//call asynchronously now
WS.GetEmployeeIDAsync (...);
}
}

protected void Page_Unload(object sender, EventArgs e)
{
WS.GetEmployeeIDCompleted -= OnGetEmployeeIDCompletedCompleted;
}

void OnGetEmployeeIDCompletedCompleted (Object source,
GetEmployeeIDCompletedEventArgs e)
{
// Use web service return (that is e.Result) to do something
}

2. I used WSPBuilder to create a sharepoint web part. In addition, I insert
the Ajax's ScriptManager to this web part so that the user control from above
is equipped with Ajax feature.

3. Deploy the web part feature from #2. The deploy has no problem. However,
when adding this web part to a sharepoint page, it has error. The reason is
the asynchronous call "WS.GetEmployeeIDAsync()" inside the Page_Load method.
Sharepoint page directive cannot accept async attribute (i.e., you cannot
setup async="true"). Now, if I commented out the statement
"WS.GetEmployeeIDAsync()", the web part can be added to the sharepoint page
without error.

So, I used web service proxy to make asynchronous call with no success. But
you used another way, which was Page.RegisterAsyncTask with success. Why it
is so? The method I used and yours should achieve the same result of
registering asynchronous web service on the sharepoint page.

Any thought? Thanks.

Pat

Chris Givens

unread,
Oct 6, 2009, 11:27:23 PM10/6/09
to
To be honest, not really. If I was to make a guess it is that they aren't
doing the async in the same way, possibly to do with threading on the page
request in asp.net versus an async call in a windows application with web
service proxies.

Hope my way works for you though!
Chris

"Pat" <Pa...@newsgroups.nospam> wrote in message

news:188C5B23-79FF-4809...@microsoft.com...

Pat

unread,
Oct 9, 2009, 5:57:02 PM10/9/09
to
Hi Chris,

I used your methods for my user control and then plug in the user control to
a sharepoint web part. It works. Thanks for your suggestion.

Pat

--
Pat

0 new messages