Ask a questionAsk a question
 

AnswerRender webservice content in a webpart

  • Thursday, November 12, 2009 12:33 AMchakrimalraj Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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

  • Friday, November 13, 2009 4:03 AMAaron Han - MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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:

           http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/81e5af26-91d9-482c-98e3-915375cce358

           For asynchronous WebPart, please refer this:

           http://daniellarson.spaces.live.com/blog/cns!D3543C5837291E93!192.entry

     

           Hope this can help.

    Best Regards,

    -Aaron

  • Friday, November 13, 2009 10:11 AMRajesh.Sitaraman Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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.
  • Friday, November 13, 2009 10:13 AMRajesh.Sitaraman Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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.

All Replies

  • Friday, November 13, 2009 4:03 AMAaron Han - MSFTModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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:

           http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/81e5af26-91d9-482c-98e3-915375cce358

           For asynchronous WebPart, please refer this:

           http://daniellarson.spaces.live.com/blog/cns!D3543C5837291E93!192.entry

     

           Hope this can help.

    Best Regards,

    -Aaron

  • Friday, November 13, 2009 10:11 AMRajesh.Sitaraman Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    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.
  • Friday, November 13, 2009 10:13 AMRajesh.Sitaraman Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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.