简体   繁体   English

WOPI 主机实现,尝试在 iframe asp.net mvc 中呈现文档

[英]WOPI Host implementation, trying to render doc in iframe asp.net mvc

I'm trying to get Wopi host implementation in an ASP.NET MVC application.我正在尝试在 ASP.NET MVC 应用程序中获得 Wopi 主机实现。

Using this project https://code.msdn.microsoft.com/office/Building-an-Office-Web-f98650d6使用这个项目https://code.msdn.microsoft.com/office/Building-an-Office-Web-f98650d6

I don't get any calls hitting my API Controler我的 API 控制器没有收到任何调用

在此处输入图片说明

Discovery URL发现网址

<action name="view"
              ext="docx"
              default="true"
              urlsrc="http://word-edit.officeapps.live.com/wv/wordviewerframe.aspx?&lt;ui=UI_LLCC&amp;&gt;&lt;rs=DC_LLCC&amp;&gt;&lt;showpagestats=PERFSTATS&amp;&gt;" />

URL generated by my application我的应用程序生成的 URL

http://word-edit.officeapps.live.com/we/wordeditorframe.aspx?WOPISrc=http%3a%2f%2flocalhost%3a32876%2fapi%2fwopi%2ffiles%2ftest.docx&access_token=XskWxXK0Nro%3dhwYoiCFehrYAx85XQduYQHYQE9EEPC6EVgqaMiCp4%2bg%3d http://word-edit.officeapps.live.com/we/wordeditorframe.aspx?WOPISrc=http%3a%2f%2flocalhost%3a32876%2fapi%2fwopi%2ffiles%2ftest.docx&access_token=XskWxXK0Nro%3dhwYoiCFeh%QehrYaPCYpMi85QEHRYpMi

I am using Local Host for testing purpose我使用本地主机进行测试

Controller Route控制器路由

 [RoutePrefix("api/wopi")]
        public class FilesController : ApiController


[Route("files/{name}/")]
        public CheckFileInfo GetFileInfo(string name, string access_token)
        {
            Validate(name, access_token);

            var fileInfo = _fileHelper.GetFileInfo(name);

            bool updateEnabled = false;
            if (bool.TryParse(WebConfigurationManager.AppSettings["updateEnabled"].ToString(), out updateEnabled))
            {
                fileInfo.SupportsUpdate = updateEnabled;
                fileInfo.UserCanWrite = updateEnabled;
                fileInfo.SupportsLocks = updateEnabled;
            }

            return fileInfo;
        }

        // GET api/<controller>/5
        /// <summary>
        /// Get a single file contents
        /// </summary>
        /// <param name="name">filename</param>
        /// <returns>a file stream</returns>
        [Route("files/{name}/contents")]
        public HttpResponseMessage Get(string name, string access_token)
        {
            try
            {
                Validate(name, access_token);
                var file = HostingEnvironment.MapPath("~/App_Data/" + name);
                var responseMessage = new HttpResponseMessage(HttpStatusCode.OK);
                var stream = new FileStream(file, FileMode.Open, FileAccess.Read);

                responseMessage.Content = new StreamContent(stream);
                responseMessage.Content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                return responseMessage;

            }
            catch (Exception ex)
            {
                var errorResponseMessage = new HttpResponseMessage(HttpStatusCode.InternalServerError);
                var stream = new MemoryStream(UTF8Encoding.Default.GetBytes(ex.Message ?? ""));
                errorResponseMessage.Content = new StreamContent(stream);
                return errorResponseMessage;
            }

        }

It is not hitting to the API URL它没有访问 API URL

WOPISrc cannot be 'localhost', it must be a link that office application server can access, WOPISrc不能是'localhost',必须是office应用服务器可以访问的链接,

While you use office online application, then you need to provide a public ip or domain name of your wopi server instead of 'localhost'当您使用office在线应用程序时,您需要提供您的wopi服务器的公共IP或域名而不是'localhost'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM