ChatBot retrieve data from SharePoint On Premise Issue

为君一笑 提交于 2020-03-03 06:55:52

问题


I've developed a chatbot that communicates with SharePoint on Premise,

When I run the chatbot in Emulator its work.

But When I run at Web that hosted outside of SharePoint, it does not work.

Herewith my screenshot of Error On Azure, From the result of Error is starting from XMLReader and SyndicationFeed

Success in Local Emulator

Herewith my Souce Code.

 private async Task ProcessRSSAsync(ITurnContext<IMessageActivity> turnContext, LuisResult luisResult, string intent, CancellationToken cancellationToken)
        {
            var questionluis = turnContext.Activity.Text;

            await turnContext.SendActivityAsync("intent recognize" + intent);

            var intentresut = intent;
            await turnContext.SendActivityAsync("Get LUIS Entity");
            await turnContext.SendActivityAsync(string.Join("\t", luisResult.Entities.Select((entityObj) => entityObj.Entity)));
            var entityfound = string.Join("\t", luisResult.Entities.Select((entityObj) => entityObj.Entity));

            string spxurl = @"https://intra.aspac.com/sites/sg/daw/_layouts/15/srchrss.aspx?k=*%20ListId:7BC0F2C3-6366-48B8-B88A-8738BE1F9C31";

            await turnContext.SendActivityAsync("Intent: " + intent.ToString() + " Entity: " + entityfound.ToString());
            ////---------------------------------------------------------------------------------------------
            //22112019
            try
            {

                //#ES09122019
                var credentials = new NetworkCredential("email@example.com", "Pa$$w0rd", "sg.kworld.com");

                var handler = new HttpClientHandler { Credentials = credentials, UseDefaultCredentials = false };
                var client = new HttpClient(handler);

                client.BaseAddress = new Uri("https://intra.aspac.com/sites/sg/daw/");

                HttpResponseMessage resp = client.GetAsync("_layouts/15/srchrss.aspx?k=" + entityfound + "*%20ListId:7BC0F2C3-6366-48B8-B88A-8738BE1F9C31").Result;

                string respString = resp.Content.ReadAsStringAsync().Result;


                if (resp.StatusCode == HttpStatusCode.OK)
                {
                    await turnContext.SendActivityAsync("Connected");

                    //Success 06122019 .
                    try
                    {
                        string spurl = @"https://intra.aspac.com/sites/sg/daw/_layouts/15/srchrss.aspx?k=*%20ListId:7BC0F2C3-6366-48B8-B88A-8738BE1F9C31";
                        XmlSecureResolver resolver = new XmlSecureResolver(new XmlUrlResolver(), spurl);
                        resolver.Credentials = new NetworkCredential("email@example.com.sg", "Pa$$w0rd", "sg.kworld.com"); 

                        XmlReaderSettings settings = new XmlReaderSettings();
                        settings.DtdProcessing = DtdProcessing.Parse;
                        settings.ValidationType = ValidationType.DTD;

                        settings.XmlResolver = resolver;



                        XmlReader reader = XmlReader.Create(spurl, settings);

                        SyndicationFeed feed = SyndicationFeed.Load(reader);

                        reader.Close();

                        var attachments = new List<Attachment>();
                        foreach (SyndicationItem item in feed.Items)
                        {
                            //Get Title,Description,URL
                            String title = item.Title.Text;
                            String description = item.Summary.Text;
                            String link = item.Links.FirstOrDefault().Uri.ToString();

                            //Hero Card
                            var heroCard = new HeroCard(
                                title: item.Title.Text,
                                // subtitle: description,
                                buttons: new CardAction[]
                                {
                         new CardAction(ActionTypes.OpenUrl,"Learn More",value:link)
                                }
                                ).ToAttachment();
                            attachments.Add(heroCard);

                        }
                        var reply = MessageFactory.Carousel(attachments);
                        await turnContext.SendActivityAsync(reply);
                        await ProcessCosmoDBStorageLUISAsync(turnContext, questionluis, intent, entityfound, respString, cancellationToken);
                    }
                    catch (Exception ex)
                    {
                        await turnContext.SendActivityAsync(ex.ToString());
                    }

                }
            }

            catch (Exception ex)
            {
                await turnContext.SendActivityAsync("Sorry,Currently Server Under Maintenace");
                await turnContext.SendActivityAsync(ex.ToString());
            }

        }

any solution for this and suggestion?


回答1:


ok, I think I finally understand this better, so hopefully can put a useful reply together. Would be much easier if we had a shared whiteboard :-)

Basically, in terms of hosting a bot on the Microsoft Bot Framework Services, you need to have a registration in Azure. However, there are two different options, and both are VERY different in terms of hosting. When you "create" the resource in Azure, and search for "Bot", you'll see two options - "Web App Bot" and "Bot Channels Registration":

  1. "Bot Channels Registration" means JUST registering your bot in Azure, but HOSTING it elsewhere.
  2. "Web App Bot" - INCLUDES the "Bot Channels Registration" but ALSO adds hosting using an Azure Web Application (so it's a Bot registration PLUS hosting)

From the screenshot you posted, I can see you've selected (2) above, and so your bot is running inside Azure, and therefore can't connect to your on premises resource (SharePoint).

As a result, I'd suggest one of two options:

  1. Create an Azure Application Proxy - this is basically a small gateway so that your bot HOSTED in Azure can securely talk to your on-premises SharePoint. There is in fact a specific use case for SharePoint in particular.

  2. Delete and re-create your Azure Bot entry to instead be just a "Bot Channels Registration", and then in the "Settings" screen you can call a bot hosted at any "https" endpoint. You can then have your bot run on the local network, but it will need a live "https" address (not -that- hard to do, but you have to involve your IT team to get a live web address, like "whatever.aspac.com", and you'll need an SSL/TLS certificate so that it can run httpS instead of just http.

Which option you choose might depend on the skills and resources on your team, as well as in the organisation. For instance, the company might have Azure Application Proxy configured already, in which case that saves a lot of work. It might have a wildcard certificate, which would make option (2) easier, etc.

Either way, I hope that helped, but feel free to ask more if anything is still unclear.




回答2:


i had a similar problem using a on premise database. as you are deploying your bot externally, the bot needs resources that are available on the internet, and not contained internally. It will work fine using the bot emulator because it has access to what your machine has.

Saying that, azure has developed some actions which you can use to help this problem. If you look at application proxys, that may be able to help you out.

i think thats what you mean... anyway!



来源:https://stackoverflow.com/questions/59368817/chatbot-retrieve-data-from-sharepoint-on-premise-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!