4

I'm trying to get Wopi host implementation in an ASP.NET MVC application.

Using this project https://code.msdn.microsoft.com/office/Building-an-Office-Web-f98650d6

I don't get any calls hitting my API Controler

enter image description here

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

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

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

rocky
  • 7,506
  • 3
  • 33
  • 48
ZCoder
  • 2,155
  • 5
  • 25
  • 62

1 Answers1

3

WOPISrc cannot be 'localhost', it must be a link that office application server can access,

While you use office online application, then you need to provide a public ip or domain name of your wopi server instead of 'localhost'

Hassan Alhaj
  • 333
  • 3
  • 11
  • 2
    In other words, the WOPI Client (Office Online Server) will use the URL provided in WOPISrc to access the binary data of the file and if the URL points to localhost, the WOPI Client (OOS) will try to obtain the file from its own machine. It's not likely that you run the WOPI Host on the same machine as WOPI Client. – rocky Aug 05 '19 at 20:53
  • @Hassan I'm using domain name to open files, but still I'm getting this error, following is my url " https://word-view.officeapps.live.com/wv/wordviewerframe.aspx?src=https://domain:portNum/wopi/files/fileId" – Shinchan Nov 19 '22 at 17:08