/// <summary> /// This method is used to send the cell storage request to the server. /// </summary> /// <param name="url">Specifies the URL of the file to edit.</param> /// <param name="subRequests">Specifies the sub request array.</param> /// <param name="requestToken">Specifies a non-negative request token integer that uniquely identifies the Request <seealso cref="Request"/>.</param> /// <param name="version">Specifies the version number of the request, whose value should only be 2.</param> /// <param name="minorVersion">Specifies the minor version number of the request, whose value should only be 0 or 2.</param> /// <param name="interval">Specifies a nonnegative integer in seconds, which the protocol client will repeat this request, the default value is null.</param> /// <param name="metaData">Specifies a 32-bit value that specifies information about the scenario and urgency of the request, the default value is null.</param> /// <returns>Returns the CellStorageResponse message received from the server.</returns> public CellStorageResponse CellStorageRequest( string url, SubRequestType[] subRequests, string requestToken = "1", ushort? version = 2, ushort? minorVersion = 2, uint? interval = null, int? metaData = null) { // If the transport is HTTPS, then try to accept the certificate. if ("HTTPS".Equals(Common.GetConfigurationPropertyValue("TransportType", this.Site), StringComparison.OrdinalIgnoreCase)) { Common.AcceptServerCertificate(); } ICellStoragesChannel channel = channelManager.CreateChannel<ICellStoragesChannel>(SharedContext.Current); // Store the SubRequestToken, subRequest type pairs this.subResponseValidationWrappers.Clear(); if (subRequests != null) { foreach (SubRequestType item in subRequests) { this.subResponseValidationWrappers.Add(new SubResponseValidationWrapper { SubToken = item.SubRequestToken, SubRequestType = item.GetType().Name }); } } // Create web request message. RequestMessageBodyWriter fsshttpBodyWriter = new RequestMessageBodyWriter(version, minorVersion); fsshttpBodyWriter.AddRequest(url, subRequests, requestToken, interval, metaData); this.lastRawRequestXml = fsshttpBodyWriter.MessageBodyXml; // Try to log the request body information this.Site.Log.Add(LogEntryKind.Debug, "The raw xml request message is:\r\n{0}", this.lastRawRequestXml.OuterXml); Message request = Message.CreateMessage(MessageVersion.Soap11, ActionURL, fsshttpBodyWriter); try { // Invoke the web service Message response = channel.ExecuteCellStorageRequest(request); // Extract and de-serialize the response. CellStorageResponse cellStorageResponseObjects = this.GetCellStorageResponseObject(response); // Restore the current version type SharedContext.Current.CellStorageVersionType = cellStorageResponseObjects.ResponseVersion; // Schema Validation for the response. this.ValidateGenericType(cellStorageResponseObjects, requestToken); this.ValidateSpecificType(cellStorageResponseObjects); request.Close(); return cellStorageResponseObjects; } catch (EndpointNotFoundException ex) { // Here try to catch the EndpointNotFoundException due to X-WOPI-ServerError. if (ex.InnerException is WebException) { if ((ex.InnerException as WebException).Response.Headers.AllKeys.Contains<string>("X-WOPI-ServerError")) { throw new WOPIServerErrorException( (ex.InnerException as System.Net.WebException).Response.Headers["X-WOPI-ServerError"], ex.InnerException); } } request.Close(); throw; } }
/// <summary> /// This method is used to send the cell storage request to the server. /// </summary> /// <param name="url">Specifies the URL of the file to edit.</param> /// <param name="subRequests">Specifies the sub request array.</param> /// <param name="requestToken">Specifies a non-negative request token integer that uniquely identifies the Request <seealso cref="Request"/>.</param> /// <param name="version">Specifies the version number of the request, whose value should only be 2.</param> /// <param name="minorVersion">Specifies the minor version number of the request, whose value should only be 0 or 2.</param> /// <param name="interval">Specifies a nonnegative integer in seconds, which the protocol client will repeat this request, the default value is null.</param> /// <param name="metaData">Specifies a 32-bit value that specifies information about the scenario and urgency of the request, the default value is null.</param> /// <param name="lastModifiedTime">Specify the last modified time, which is expressed as a tick count.</param> /// <param name="parentFolderResourceID">If UseResourceID is true, this parameter tells the host to create a file in the given folder ResourceID, regardless of the request URL value.</param> /// <param name="shouldReturnDisambiguatedFileName">If an upload request fails with a coherency failure, this flag specifies whether the host should return a suggested/available file name that the client can try instead</param> /// <param name="resourceID">Specify the invariant ResourceID for a file that uniquely identifies the file whose response is being generated</param> /// <param name="useResourceID">Specify if the protocol server MAY perform ResourceID specific behavior for the file whose contents or metadata contents are requested for uploading to the server or downloading from the server. </param> /// <returns>Returns the CellStorageResponse message received from the server.</returns> public CellStorageResponse CellStorageRequest( string url, SubRequestType[] subRequests, string requestToken = "1", ushort?version = 2, ushort?minorVersion = 2, uint?interval = null, int?metaData = null, string lastModifiedTime = null, string parentFolderResourceID = null, bool?shouldReturnDisambiguatedFileName = null, string resourceID = null, bool?useResourceID = null) { // If the transport is HTTPS, then try to accept the certificate. if ("HTTPS".Equals(Common.GetConfigurationPropertyValue("TransportType", this.Site), StringComparison.OrdinalIgnoreCase)) { Common.AcceptServerCertificate(); } ICellStoragesChannel channel = channelManager.CreateChannel <ICellStoragesChannel>(SharedContext.Current); // Store the SubRequestToken, subRequest type pairs this.subResponseValidationWrappers.Clear(); if (subRequests != null) { foreach (SubRequestType item in subRequests) { this.subResponseValidationWrappers.Add(new SubResponseValidationWrapper { SubToken = item.SubRequestToken, SubRequestType = item.GetType().Name }); } } // Create web request message. RequestMessageBodyWriter fsshttpBodyWriter = new RequestMessageBodyWriter(version, minorVersion); fsshttpBodyWriter.AddRequest(url, subRequests, requestToken, interval, metaData, lastModifiedTime, parentFolderResourceID, shouldReturnDisambiguatedFileName, resourceID, useResourceID); this.lastRawRequestXml = fsshttpBodyWriter.MessageBodyXml; // Try to log the request body information this.Site.Log.Add(LogEntryKind.Debug, "The raw xml request message is:\r\n{0}", this.lastRawRequestXml.OuterXml); Message request = Message.CreateMessage(MessageVersion.Soap11, ActionURL, fsshttpBodyWriter); try { // Invoke the web service Message response = channel.ExecuteCellStorageRequest(request); // Extract and de-serialize the response. CellStorageResponse cellStorageResponseObjects = this.GetCellStorageResponseObject(response); // Restore the current version type SharedContext.Current.CellStorageVersionType = cellStorageResponseObjects.ResponseVersion; SharedContext.Current.FileUrl = url; // Schema Validation for the response. this.ValidateGenericType(cellStorageResponseObjects, requestToken); this.ValidateSpecificType(cellStorageResponseObjects); request.Close(); return(cellStorageResponseObjects); } catch (EndpointNotFoundException ex) { // Here try to catch the EndpointNotFoundException due to X-WOPI-ServerError. if (ex.InnerException is WebException) { if (((ex.InnerException as WebException).Response as HttpWebResponse).StatusCode == HttpStatusCode.NotFound) { request.Close(); return(null); } else if ((ex.InnerException as WebException).Response.Headers.AllKeys.Contains <string>("X-WOPI-ServerError")) { throw new WOPIServerErrorException( (ex.InnerException as System.Net.WebException).Response.Headers["X-WOPI-ServerError"], ex.InnerException); } } request.Close(); throw; } catch (ProtocolException) { request.Close(); return(null); } }