locked
Consume WCF Service in Lightswitch RRS feed

  • Question

  • I have a very basic WCF (non RIA) Service deployed to my local IIS, this service uses a httpwebrequest which obtains an XML file, I then parse that XML file, I then spit out a list of ID's from the XML in a list and everything works when I test it.

    Then I decided that I need to consume this list of data in Lightswitch, however, every thing I can find is based around having a database and not having the data come in from my WCF Service, is this possible?

    I've read in another thread another person was attempting this and simply was told to wrap the WCF Service inside of a WCF RIA Service then consume the RIA service with Lightswitch, however I'm at a loss how to do this?

    Is WCF even the correct way over ODATA? 

    I'm trying to learn how to consume non EF data in lightswitch through WCF but I guess I need some pointers here....

    Here is my WCF Service to give you an idea of how basic this is.

    using System;
    using System.Collections.Generic;
    using System.Configuration;
    using System.IO;
    using System.Linq;
    using System.Net;
    using System.Runtime.Serialization;
    using System.ServiceModel;
    using System.ServiceModel.Web;
    using System.Text;
    using System.Xml;
    
    namespace COID_WEB_SERVICE
    {
    
        public class Service1 : IService1
        {
    
            public List<string> getXML()
            {
                try
                {
                    string coid_url = @"http://xxxxxxx.cgi";
                    HttpWebRequest cgiCall = (HttpWebRequest)HttpWebRequest.Create(coid_url);
                    cgiCall.Credentials = CredentialCache.DefaultCredentials;
    
                    cgiCall.AuthenticationLevel = System.Net.Security.AuthenticationLevel.None;
                    cgiCall.Method = WebRequestMethods.Http.Get;
    
                    HttpWebResponse cgiResponse = (HttpWebResponse)cgiCall.GetResponse();
    
                    using (Stream responsestream = cgiResponse.GetResponseStream())
                    using (StreamReader sr = new StreamReader(responsestream))
                    {
                        string responsestring = sr.ReadToEnd();
                        var xmlDoc = new XmlDocument();
                        xmlDoc.InnerXml = responsestring;
                        XmlElement root = xmlDoc.DocumentElement;
                        int i = 0;
                        List<string> str = new List<string>();
                        foreach (XmlElement ele in root)
                        {
                            responsestring = ele.GetElementsByTagName("element")[0].InnerText;
                            str.Add(responsestring);
                        }
    
                        return str;
                    }
                }
                finally
                {
    
                }
            }
        }
    }


    Wednesday, April 3, 2013 9:54 PM

Answers

All replies