Render webservice content in a webpart
- Hello,
I am trying to retreive the data from stock webservice and render it on the web part. Since i am a beginner in this, can anyone please help me to display the stock data in a web part.
this is the web service i am using,
http://www.webservicex.net/stockquote.asmx
it is returning the xml data, which i need to capture and display on a webpart.
thanks,
Chakri
Answers
Hi,
If you wish to use OOB webpart without extra development, DataView webpart can be a solution.
However, as the stock webservice is synchronize used, if the response time of service is slow, the entire page will be blocked until the DataView renders successfully.
As a sample, see:
http://www.wssdemo.com/Pages/WebServiceDilbert.aspx
Another choice is creating a asynchronous WebPart to consume this service:
You can refer this thread:
For asynchronous WebPart, please refer this:
http://daniellarson.spaces.live.com/blog/cns!D3543C5837291E93!192.entry
Hope this can help.
Best Regards,
-Aaron
- Proposed As Answer byPeter Holpar Friday, November 13, 2009 7:42 AM
- Marked As Answer byAaron Han - MSFTModeratorFriday, November 20, 2009 1:46 AM
Another approach is you can try with JQuery
Add a Content Editor Web Part and add the below snippet in the source editor.
You have to work on the processResult function for desired presentation of the fetched stock information.
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetQuote xmlns='http://www.webserviceX.NET/'> \
<symbol>MSFT</symbol> \
</GetQuote> \
</soapenv:Body> \
</soapenv:Envelope>";$.ajax({
url: "http://www.webservicex.net/stockquote.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});
});function processResult(xData, status) {
var liHtml =$(xData.responseXML.text);
$("#stockUL").append(liHtml);
}
</script>
<ul id="stockUL"/>
---
Rajesh | My Blog
MCTS - WSS AD, WSS Config, MOSS Config.- Proposed As Answer byAaron Han - MSFTModeratorMonday, November 16, 2009 1:45 AM
- Marked As Answer byAaron Han - MSFTModeratorFriday, November 20, 2009 1:46 AM
- I have hardcoded stock symbol, which has to be changed accordingly.
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetQuote xmlns='http://www.webserviceX.NET/'> \
<symbol>MSFT</symbol> \
</GetQuote> \
</soapenv:Body> \
</soapenv:Envelope>";
---
Rajesh | My Blog
MCTS - WSS AD, WSS Config, MOSS Config.- Marked As Answer byAaron Han - MSFTModeratorFriday, November 20, 2009 1:46 AM
All Replies
Hi,
If you wish to use OOB webpart without extra development, DataView webpart can be a solution.
However, as the stock webservice is synchronize used, if the response time of service is slow, the entire page will be blocked until the DataView renders successfully.
As a sample, see:
http://www.wssdemo.com/Pages/WebServiceDilbert.aspx
Another choice is creating a asynchronous WebPart to consume this service:
You can refer this thread:
For asynchronous WebPart, please refer this:
http://daniellarson.spaces.live.com/blog/cns!D3543C5837291E93!192.entry
Hope this can help.
Best Regards,
-Aaron
- Proposed As Answer byPeter Holpar Friday, November 13, 2009 7:42 AM
- Marked As Answer byAaron Han - MSFTModeratorFriday, November 20, 2009 1:46 AM
Another approach is you can try with JQuery
Add a Content Editor Web Part and add the below snippet in the source editor.
You have to work on the processResult function for desired presentation of the fetched stock information.
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var soapEnv =
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetQuote xmlns='http://www.webserviceX.NET/'> \
<symbol>MSFT</symbol> \
</GetQuote> \
</soapenv:Body> \
</soapenv:Envelope>";$.ajax({
url: "http://www.webservicex.net/stockquote.asmx",
type: "POST",
dataType: "xml",
data: soapEnv,
complete: processResult,
contentType: "text/xml; charset=\"utf-8\""
});
});function processResult(xData, status) {
var liHtml =$(xData.responseXML.text);
$("#stockUL").append(liHtml);
}
</script>
<ul id="stockUL"/>
---
Rajesh | My Blog
MCTS - WSS AD, WSS Config, MOSS Config.- Proposed As Answer byAaron Han - MSFTModeratorMonday, November 16, 2009 1:45 AM
- Marked As Answer byAaron Han - MSFTModeratorFriday, November 20, 2009 1:46 AM
- I have hardcoded stock symbol, which has to be changed accordingly.
"<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
<soapenv:Body> \
<GetQuote xmlns='http://www.webserviceX.NET/'> \
<symbol>MSFT</symbol> \
</GetQuote> \
</soapenv:Body> \
</soapenv:Envelope>";
---
Rajesh | My Blog
MCTS - WSS AD, WSS Config, MOSS Config.- Marked As Answer byAaron Han - MSFTModeratorFriday, November 20, 2009 1:46 AM

