Quantcast
Channel: Microsoft Online: SharePoint Online forum
Viewing all articles
Browse latest Browse all 10096

View Word/Excel/PDF documents from SQL on-premises databse table containing files on SharePoint 2013 Online by way of WCF Service

$
0
0

How to create a list of documents and also be able to open them in SharePoint 2013 online?

The documents are stored in an on-premise SQL Server database table.

How I was going about it was to

  1. Create a WCF service in Visual Studio
  2. Host that service in IIS
  3. Create an External Content Type in SharePoint Online
  4. Add the WCF service connection
  5. Export and Edit the BDC model from SharePoint Online BCS to include <MethodInstance Type="StreamAccess"...
  6. Import the BDC model back to SharePoint Online BCS
  7. Create a List
  8. Click on the link and open the file

I'm having issues after step 6...

I successfully imported the BDC model back into SharePoint Online BCS, but I don't know how to create a list with the document link. I also don't know if my code is correct within the WCF service or the BDC model I edited.  I am using a byte[] (byte array) to pass an image sql datatype.  See code and picture below:

This is what happens if I try to edit the DocumentReadStream Operation....

---------------------------------------------------------------------------------------------------------------------------------------------
Code for the WCF service.........WCF_DocService.cs

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;
using System.Configuration;
using System.Data;

namespace WCF_DocService
{
    
    class WCF_DocService : IWCF_DocService
    {
        


        public List<Documents> Get50Documents(int id)
        {
            List<Documents> LD = new List<Documents>();

            string ConStr = "data source=server_name; initial catalog=database_name; integrated security=False; User ID=xxxxxxx; Password=xxxxxx";

            SqlConnection con = new SqlConnection(ConStr);
            SqlCommand cmd = new SqlCommand("Select TOP 2 DocumentID, DmeName, DmePermissions, Content FROM DME_SP", con);
            con.Open();
            SqlDataReader dr = cmd.ExecuteReader();

            while(dr.Read())
            {
                Documents d = new Documents();
                d.DocumentID = int.Parse(dr[0].ToString());
                d.DmeName = dr[1].ToString();
                d.DmePermissions = dr[2].ToString();
                d.Content = (byte[])dr[3]; 
                LD.Add(d);
            }
            dr.Close();
            con.Close();

            return LD;
        }
    }
}

------------------------------------------------------------------------------------------------------------------------------------------------------
Code for the Interface.....IWCF_DocService.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.Threading.Tasks;

namespace WCF_DocService
{
    [ServiceContract]
    interface IWCF_DocService
    {
        [OperationContract]
        List<Documents> Get50Documents(int id);


    }

    [DataContract]
    public class Documents
    {
        [DataMember]
        public int DocumentID { get; set; }
        [DataMember]
        public string DmeName { get; set; }
        [DataMember]
        public string DmePermissions { get; set; }
        [DataMember]
        public byte[] Content { get; set; }
       
        
    }


}

--------------------------------------------------------------------------------------------------------------------------------------------------
Code for the IISHost website, with a reference to the WCF service......Service.svc

<%@ ServiceHost Language="C#" Debug="true" Service="WCF_DocService.WCF_DocService"%>
--------------------------------------------------------------------------------------------------------------------------------------------------
Code for the IISHost website, with a reference to the WCF service......Web.config<?xml version="1.0"?><configuration><system.serviceModel><serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" /><services><service name="WCF_DocService.WCF_DocService" behaviorConfiguration="mexBehavior"><endpoint address="DocService"
                  binding="basicHttpBinding" 
                  contract="WCF_DocService.IWCF_DocService"></endpoint><endpoint address="mex"
                  binding="mexHttpBinding"
                  contract="IMetadataExchange" /><host><baseAddresses><add baseAddress="http://code_removed_for_security/"/></baseAddresses></host></service></services><behaviors><serviceBehaviors><behavior name="mexBehavior"><serviceMetadata httpGetEnabled="true" /><useRequestHeadersForMetadataAddress /><serviceDebug includeExceptionDetailInFaults="true" /></behavior><behavior name=""><serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" /><serviceDebug includeExceptionDetailInFaults="false" /></behavior></serviceBehaviors></behaviors></system.serviceModel></configuration>
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
BDC model code where I added a <methodinstance type="StreamAccessor"<?xml version="1.0" encoding="utf-16" standalone="yes"?><Model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schemas.microsoft.com/windows/2007/BusinessDataCatalog BDCMetadata.xsd" Name="Doc" xmlns="http://schemas.microsoft.com/windows/2007/BusinessDataCatalog"><AccessControlList><AccessControlEntry Principal="STS|SecurityTokenService|http://sharepoint.microsoft.com/claims/2009/08/isauthenticated|true|http://www.w3.org/2001/XMLSchema#string"><Right BdcRight="Edit" /><Right BdcRight="Execute" /><Right BdcRight="SelectableInClients" /></AccessControlEntry><AccessControlEntry Principal="membership:code_removed_for_security_reasons"><Right BdcRight="Edit" /><Right BdcRight="Execute" /><Right BdcRight="SetPermissions" /><Right BdcRight="SelectableInClients" /></AccessControlEntry></AccessControlList><LobSystems><LobSystem Type="Wcf" Name="http://code_removed_for_security_reasons/DocService/Service.svc?wsdl"><Properties><Property Name="ReferenceKnownTypes" Type="System.Boolean">true</Property><Property Name="WcfMexDiscoMode" Type="System.String">Disco</Property><Property Name="WcfMexDocumentUrl" Type="System.String">http://code_removed_for_security_reasons/DocService/Service.svc?wsdl</Property><Property Name="WcfProxyNamespace" Type="System.String">BCSServiceProxy</Property><Property Name="WildcardCharacter" Type="System.String">*</Property><Property Name="WsdlFetchAuthenticationMode" Type="System.String">PassThrough</Property></Properties><AccessControlList><AccessControlEntry Principal="STS|SecurityTokenService|http://sharepoint.microsoft.com/claims/2009/08/isauthenticated|true|http://www.w3.org/2001/XMLSchema#string"><Right BdcRight="Edit" /><Right BdcRight="Execute" /><Right BdcRight="SelectableInClients" /></AccessControlEntry><AccessControlEntry Principal="membership:code_removed_for_security_reasons"><Right BdcRight="Edit" /><Right BdcRight="Execute" /><Right BdcRight="SetPermissions" /><Right BdcRight="SelectableInClients" /></AccessControlEntry></AccessControlList><Proxy>..........code removed............</Proxy><LobSystemInstances><LobSystemInstance Name="http://code_removed_for_security_reasons/DocService/Service.svc?wsdl"><Properties><Property Name="ShowInSearchUI" Type="System.String"></Property><Property Name="WcfAuthenticationMode" Type="System.String">PassThrough</Property><Property Name="WcfEndpointAddress" Type="System.String">http://code_removed_for_security_reasons/DocService/Service.svc/DocService</Property></Properties></LobSystemInstance></LobSystemInstances><Entities><Entity Namespace="https://code_removed_for_security_reasons.sharepoint.com/dme" Version="1.4.0.0" EstimatedInstanceCount="10000" Name="DOC" DefaultDisplayName="DOC"><Properties><Property Name="ExcludeFromOfflineClientForList" Type="System.Boolean">true</Property></Properties><AccessControlList><AccessControlEntry Principal="membership:yoder@cgfs.onmicrosoft.com"><Right BdcRight="Edit" /><Right BdcRight="Execute" /><Right BdcRight="SetPermissions" /><Right BdcRight="SelectableInClients" /></AccessControlEntry></AccessControlList><Identifiers><Identifier TypeName="System.Int32" Name="DocumentID" /></Identifiers><Methods><Method IsStatic="false" LobName="Get50Documents" Name="Get50Documents2"><AccessControlList><AccessControlEntry Principal="membership:code_removed_for_security_reasons"><Right BdcRight="Edit" /><Right BdcRight="Execute" /><Right BdcRight="SetPermissions" /><Right BdcRight="SelectableInClients" /></AccessControlEntry></AccessControlList><Parameters><Parameter Direction="In" Name="id"><TypeDescriptor TypeName="System.Int32" Name="id" /></Parameter><Parameter Direction="Return" Name="Get50Documents"><TypeDescriptor TypeName="BCSServiceProxy.Documents[], http://code_removed_for_security_reasons/DocService/Service.svc?wsdl" IsCollection="true" Name="Get50Documents"><TypeDescriptors><TypeDescriptor TypeName="BCSServiceProxy.Documents, http://code_removed_for_security_reasons/DocService/Service.svc?wsdl" Name="Get50DocumentsElement"><TypeDescriptors><TypeDescriptor TypeName="System.String" Name="DmeName" /><TypeDescriptor TypeName="System.String" Name="DmePermissions" /><TypeDescriptor TypeName="System.Int32" ReadOnly="true" IdentifierName="DocumentID" Name="DocumentID" /></TypeDescriptors></TypeDescriptor></TypeDescriptors></TypeDescriptor></Parameter></Parameters><MethodInstances><MethodInstance Type="Finder" ReturnParameterName="Get50Documents" Default="true" Name="Get50Documents2" DefaultDisplayName="DOC Read List"><Properties><Property Name="RootFinder" Type="System.String"></Property><Property Name="UseClientCachingForSearch" Type="System.String"></Property></Properties><AccessControlList><AccessControlEntry Principal="membership:code_removed_for_security_reasons"><Right BdcRight="Edit" /><Right BdcRight="Execute" /><Right BdcRight="SetPermissions" /><Right BdcRight="SelectableInClients" /></AccessControlEntry></AccessControlList></MethodInstance></MethodInstances></Method><Method IsStatic="false" Name="Get50Documents"><AccessControlList><AccessControlEntry Principal="membership:code_removed_for_security_reasons"><Right BdcRight="Edit" /><Right BdcRight="Execute" /><Right BdcRight="SetPermissions" /><Right BdcRight="SelectableInClients" /></AccessControlEntry></AccessControlList><Parameters><Parameter Direction="In" Name="id"><TypeDescriptor TypeName="System.Int32" IdentifierName="DocumentID" Name="id" /></Parameter><Parameter Direction="Return" Name="Get50Documents"><TypeDescriptor TypeName="BCSServiceProxy.Documents[], http://code_removed_for_security_reasons/DocService/Service.svc?wsdl" IsCollection="true" Name="Get50Documents"><TypeDescriptors><TypeDescriptor TypeName="BCSServiceProxy.Documents, http://code_removed_for_security_reasons/DocService/Service.svc?wsdl" Name="Get50DocumentsElement"><TypeDescriptors><TypeDescriptor TypeName="System.String" Name="DmeName" /><TypeDescriptor TypeName="System.String" Name="DmePermissions" /><TypeDescriptor TypeName="System.Int32" ReadOnly="true" IdentifierName="DocumentID" Name="DocumentID" /></TypeDescriptors></TypeDescriptor></TypeDescriptors></TypeDescriptor></Parameter></Parameters><MethodInstances><MethodInstance Type="SpecificFinder" ReturnParameterName="Get50Documents" ReturnTypeDescriptorPath="Get50Documents[0]" Default="true" Name="Get50Documents" DefaultDisplayName="Read Item DOC"><Properties><Property Name="LastDesignedOfficeItemType" Type="System.String">None</Property></Properties><AccessControlList><AccessControlEntry Principal="membership:code_removed_for_security_reasons"><Right BdcRight="Edit" /><Right BdcRight="Execute" /><Right BdcRight="SetPermissions" /><Right BdcRight="SelectableInClients" /></AccessControlEntry></AccessControlList></MethodInstance></MethodInstances></Method> 
---------------------------------------------------------------------
Code I added....<Method IsStatic="false" Name="DocumentReadStream"><AccessControlList><AccessControlEntry Principal="membership:code_removed_for_security_reasons"><Right BdcRight="Edit" /><Right BdcRight="Execute" /><Right BdcRight="SetPermissions" /><Right BdcRight="SelectableInClients" /></AccessControlEntry></AccessControlList><Parameters><Parameter Direction="In" Name="id"><TypeDescriptor TypeName="System.Int32" Name="id" /></Parameter><Parameter Direction="Return" Name="DocumentReadStream"><TypeDescriptor TypeName="BCSServiceProxy.Documents[], http://code_removed_for_security_reasons/DocService/Service.svc?wsdl" IsCollection="true" Name="DocumentReadStream"><TypeDescriptors><TypeDescriptor TypeName="BCSServiceProxy.Documents, http://code_removed_for_security_reasons/DocService/Service.svc?wsdl" Name="DocumentReadStreamElement"><TypeDescriptors><TypeDescriptor TypeName="System.Byte[]" Name="Content" /></TypeDescriptors></TypeDescriptor></TypeDescriptors></TypeDescriptor></Parameter></Parameters><MethodInstances><MethodInstance Type="StreamAccessor" ReturnParameterName="DocumentReadStream" ReturnTypeDescriptorPath="DocumentReadStream[0].Content" Default="true" Name="DocumentReadStream" DefaultDisplayName="Content"><AccessControlList><AccessControlEntry Principal="membership:code_removed_for_security_reasons"><Right BdcRight="Edit" /><Right BdcRight="Execute" /><Right BdcRight="SetPermissions" /><Right BdcRight="SelectableInClients" /></AccessControlEntry></AccessControlList></MethodInstance></MethodInstances></Method>
----------------------------------------------------------------------</Methods></Entity></Entities></LobSystem></LobSystems></Model>


Yoderr


Viewing all articles
Browse latest Browse all 10096

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>