- improved Web Services compatibility
- fixed a few Web Services bugs
- added additional GetObject(string) method

git-svn-id: https://svn.apache.org/repos/asf/chemistry/dotcmis/trunk@1082138 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/DotCMIS/Properties/AssemblyInfo.cs b/DotCMIS/Properties/AssemblyInfo.cs
index 736b520..622c8a2 100644
--- a/DotCMIS/Properties/AssemblyInfo.cs
+++ b/DotCMIS/Properties/AssemblyInfo.cs
@@ -32,5 +32,5 @@
 // You can specify all the values or you can default the Build and Revision Numbers 

 // by using the '*' as shown below:

 // [assembly: AssemblyVersion("1.0.*")]

-[assembly: AssemblyVersion("0.1.0.0")]

+[assembly: AssemblyVersion("0.1.1.0")]

 [assembly: AssemblyFileVersion("1.0.0.0")]

diff --git a/DotCMIS/binding/binding-intf.cs b/DotCMIS/binding/binding-intf.cs
index ca3ba34..6073a5f 100644
--- a/DotCMIS/binding/binding-intf.cs
+++ b/DotCMIS/binding/binding-intf.cs
@@ -22,6 +22,8 @@
 using DotCMIS.Binding.Impl;

 using DotCMIS.Binding.Services;

 using DotCMIS.CMISWebServicesReference;

+using System.ServiceModel.Description;

+using System.ServiceModel.Channels;

 

 namespace DotCMIS.Binding

 {

@@ -70,59 +72,98 @@
         {

             string user = GetUser();

             string password = GetPassword();

-            if (user == null || password == null)

+

+            // AtomPub authentictaion

+            WebRequest request = connection as WebRequest;

+            if (request != null)

             {

+                if (user != null || password != null)

+                {

+                    request.Credentials = new NetworkCredential(user ?? "", password ?? "");

+                }

                 return;

             }

 

-            if (connection is RepositoryServicePortClient)

+            // Web Services authentication

+            RepositoryServicePortClient repositoryServicePortClient = connection as RepositoryServicePortClient;

+            if (repositoryServicePortClient != null)

             {

-                ((RepositoryServicePortClient)connection).ClientCredentials.UserName.UserName = user;

-                ((RepositoryServicePortClient)connection).ClientCredentials.UserName.Password = password;

+                AddUsernameCredentials(repositoryServicePortClient.Endpoint, repositoryServicePortClient.ClientCredentials, user, password);

+                return;

             }

-            else if (connection is NavigationServicePortClient)

+

+            NavigationServicePortClient navigationServicePortClient = connection as NavigationServicePortClient;

+            if (navigationServicePortClient != null)

             {

-                ((NavigationServicePortClient)connection).ClientCredentials.UserName.UserName = user;

-                ((NavigationServicePortClient)connection).ClientCredentials.UserName.Password = password;

+                AddUsernameCredentials(navigationServicePortClient.Endpoint, navigationServicePortClient.ClientCredentials, user, password);

+                return;

             }

-            else if (connection is ObjectServicePortClient)

+

+            ObjectServicePortClient objectServicePortClient = connection as ObjectServicePortClient;

+            if (objectServicePortClient != null)

             {

-                ((ObjectServicePortClient)connection).ClientCredentials.UserName.UserName = user;

-                ((ObjectServicePortClient)connection).ClientCredentials.UserName.Password = password;

+                AddUsernameCredentials(objectServicePortClient.Endpoint, objectServicePortClient.ClientCredentials, user, password);

+                return;

             }

-            else if (connection is VersioningServicePortClient)

+

+            VersioningServicePortClient versioningServicePortClient = connection as VersioningServicePortClient;

+            if (versioningServicePortClient != null)

             {

-                ((VersioningServicePortClient)connection).ClientCredentials.UserName.UserName = user;

-                ((VersioningServicePortClient)connection).ClientCredentials.UserName.Password = password;

+                AddUsernameCredentials(versioningServicePortClient.Endpoint, versioningServicePortClient.ClientCredentials, user, password);

+                return;

             }

-            else if (connection is DiscoveryServicePortClient)

+

+            DiscoveryServicePortClient discoveryServicePortClient = connection as DiscoveryServicePortClient;

+            if (discoveryServicePortClient != null)

             {

-                ((DiscoveryServicePortClient)connection).ClientCredentials.UserName.UserName = user;

-                ((DiscoveryServicePortClient)connection).ClientCredentials.UserName.Password = password;

+                AddUsernameCredentials(discoveryServicePortClient.Endpoint, discoveryServicePortClient.ClientCredentials, user, password);

+                return;

             }

-            else if (connection is RelationshipServicePortClient)

+

+            RelationshipServicePortClient relationshipServicePortClient = connection as RelationshipServicePortClient;

+            if (relationshipServicePortClient != null)

             {

-                ((RelationshipServicePortClient)connection).ClientCredentials.UserName.UserName = user;

-                ((RelationshipServicePortClient)connection).ClientCredentials.UserName.Password = password;

+                AddUsernameCredentials(relationshipServicePortClient.Endpoint, relationshipServicePortClient.ClientCredentials, user, password);

+                return;

             }

-            else if (connection is MultiFilingServicePortClient)

+

+            MultiFilingServicePortClient multiFilingServicePortClient = connection as MultiFilingServicePortClient;

+            if (multiFilingServicePortClient != null)

             {

-                ((MultiFilingServicePortClient)connection).ClientCredentials.UserName.UserName = user;

-                ((MultiFilingServicePortClient)connection).ClientCredentials.UserName.Password = password;

+                AddUsernameCredentials(multiFilingServicePortClient.Endpoint, multiFilingServicePortClient.ClientCredentials, user, password);

+                return;

             }

-            else if (connection is PolicyServicePortClient)

+

+            PolicyServicePortClient policyServicePortClient = connection as PolicyServicePortClient;

+            if (policyServicePortClient != null)

             {

-                ((PolicyServicePortClient)connection).ClientCredentials.UserName.UserName = user;

-                ((PolicyServicePortClient)connection).ClientCredentials.UserName.Password = password;

+                AddUsernameCredentials(multiFilingServicePortClient.Endpoint, multiFilingServicePortClient.ClientCredentials, user, password);

+                return;

             }

-            else if (connection is ACLServicePortClient)

+

+            ACLServicePortClient aclServicePortClient = connection as ACLServicePortClient;

+            if (aclServicePortClient != null)

             {

-                ((ACLServicePortClient)connection).ClientCredentials.UserName.UserName = user;

-                ((ACLServicePortClient)connection).ClientCredentials.UserName.Password = password;

+                AddUsernameCredentials(aclServicePortClient.Endpoint, aclServicePortClient.ClientCredentials, user, password);

+                return;

             }

-            else if (connection is WebRequest)

+        }

+

+        protected void AddUsernameCredentials(ServiceEndpoint endpoint, ClientCredentials clientCredentials, string user, string password)

+        {

+            if (user != null || password != null)

             {

-                ((WebRequest)connection).Credentials = new NetworkCredential(user, password);

+                clientCredentials.UserName.UserName = user ?? "";

+                clientCredentials.UserName.Password = password ?? "";

+            }

+            else

+            {

+                CustomBinding binding = endpoint.Binding as CustomBinding;

+                if (binding != null)

+                {

+                    // remove SecurityBindingElement is neither a username nor a password have been set

+                    binding.Elements.RemoveAll<SecurityBindingElement>();

+                }

             }

         }

     }

diff --git a/DotCMIS/binding/converter.cs b/DotCMIS/binding/converter.cs
index 4ff111a..b420a16 100644
--- a/DotCMIS/binding/converter.cs
+++ b/DotCMIS/binding/converter.cs
@@ -1204,11 +1204,11 @@
             RenditionData result = new RenditionData();

             result.StreamId = rendition.streamId;

             result.MimeType = rendition.mimetype;

-            result.Length = Int64.Parse(rendition.length);

+            result.Length = rendition.length == null ? null : (long?)Int64.Parse(rendition.length);

             result.Kind = rendition.kind;

             result.Title = rendition.title;

-            result.Height = Int64.Parse(rendition.height);

-            result.Width = Int64.Parse(rendition.width);

+            result.Height = rendition.height == null ? null : (long?)Int64.Parse(rendition.height);

+            result.Width = rendition.width == null ? null : (long?)Int64.Parse(rendition.width);

             result.RenditionDocumentId = rendition.renditionDocumentId;

 

             ConvertExtension(rendition, result);

diff --git a/DotCMIS/binding/webservices/webservices.cs b/DotCMIS/binding/webservices/webservices.cs
index d27d297..5b0d813 100644
--- a/DotCMIS/binding/webservices/webservices.cs
+++ b/DotCMIS/binding/webservices/webservices.cs
@@ -26,6 +26,7 @@
 using DotCMIS.Data.Extensions;

 using DotCMIS.Exceptions;

 using DotCMIS.Enums;

+using System.ServiceModel.Channels;

 

 namespace DotCMIS.Binding.WebServices

 {

@@ -214,14 +215,37 @@
         {

             object portObject = null;

 

-            BasicHttpBinding binding = new BasicHttpBinding();

-            binding.MessageEncoding = WSMessageEncoding.Mtom;

-            binding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;

-            binding.TransferMode = TransferMode.Streamed;

+            CustomBinding binding;

 

-            long messageSize = session.GetValue(SessionParameter.MessageSize, 4 * 1024 * 1024);

-            binding.MaxReceivedMessageSize = messageSize;

-            binding.MaxBufferSize = (messageSize > Int32.MaxValue ? Int32.MaxValue : (int)messageSize);

+            string wcfBinding = session.GetValue(SessionParameter.WebServicesWCFBinding) as string;

+

+            if (wcfBinding != null)

+            {

+                binding = new CustomBinding(wcfBinding);

+            }

+            else

+            {

+                long messageSize = session.GetValue(SessionParameter.MessageSize, 4 * 1024 * 1024);

+

+                List<BindingElement> elements = new List<BindingElement>();

+

+                SecurityBindingElement securityElement = SecurityBindingElement.CreateUserNameOverTransportBindingElement();

+                securityElement.SecurityHeaderLayout = SecurityHeaderLayout.LaxTimestampFirst;

+                //securityElement.IncludeTimestamp = false;

+                elements.Add(securityElement);

+

+                MtomMessageEncodingBindingElement mtomElement = new MtomMessageEncodingBindingElement();

+                mtomElement.MessageVersion = MessageVersion.Soap11;

+                mtomElement.MaxBufferSize = (messageSize > Int32.MaxValue ? Int32.MaxValue : (int)messageSize);

+                elements.Add(mtomElement);

+

+                HttpsTransportBindingElement transportElement = new HttpsTransportBindingElement();

+                transportElement.MaxReceivedMessageSize = messageSize;

+                transportElement.TransferMode = TransferMode.Streamed;

+                elements.Add(transportElement);

+

+                binding = new CustomBinding(elements);

+            }

 

             if (serviceKey == SessionParameter.WebServicesRepositoryService)

             {

@@ -509,7 +533,7 @@
 

             try

             {

-                cmisObjectInFolderContainerType[] descendants = port.getDescendants(repositoryId, folderId, filter, depth.ToString(),

+                cmisObjectInFolderContainerType[] descendants = port.getDescendants(repositoryId, folderId, depth.ToString(), filter,

                     includeAllowableActions, (enumIncludeRelationships?)CmisValue.CmisToSerializerEnum(includeRelationships),

                     renditionFilter, includePathSegment, Converter.ConvertExtension(extension));

 

@@ -544,7 +568,7 @@
 

             try

             {

-                cmisObjectInFolderContainerType[] descendants = port.getFolderTree(repositoryId, folderId, filter, depth.ToString(),

+                cmisObjectInFolderContainerType[] descendants = port.getFolderTree(repositoryId, folderId, depth.ToString(), filter,

                     includeAllowableActions, (enumIncludeRelationships?)CmisValue.CmisToSerializerEnum(includeRelationships),

                     renditionFilter, includePathSegment, Converter.ConvertExtension(extension));

 

diff --git a/DotCMIS/client/client-impl.cs b/DotCMIS/client/client-impl.cs
index 7461469..7dc508e 100644
--- a/DotCMIS/client/client-impl.cs
+++ b/DotCMIS/client/client-impl.cs
@@ -473,6 +473,21 @@
             {

                 throw new ArgumentException("Object Id must be set!");

             }

+

+            return GetObject(objectId.Id, context);

+        }

+

+        public ICmisObject GetObject(string objectId)

+        {

+            return GetObject(objectId, DefaultContext);

+        }

+

+        public ICmisObject GetObject(string objectId, IOperationContext context)

+        {

+            if (objectId == null)

+            {

+                throw new ArgumentException("Object Id must be set!");

+            }

             if (context == null)

             {

                 throw new ArgumentException("Operation context must be set!");

@@ -483,7 +498,7 @@
             // ask the cache first

             if (context.CacheEnabled)

             {

-                result = Cache.GetById(objectId.Id, context.CacheKey);

+                result = Cache.GetById(objectId, context.CacheKey);

                 if (result != null)

                 {

                     return result;

@@ -491,7 +506,7 @@
             }

 

             // get the object

-            IObjectData objectData = Binding.GetObjectService().GetObject(RepositoryId, objectId.Id, context.FilterString,

+            IObjectData objectData = Binding.GetObjectService().GetObject(RepositoryId, objectId, context.FilterString,

                 context.IncludeAllowableActions, context.IncludeRelationships, context.RenditionFilterString, context.IncludePolicies,

                 context.IncludeAcls, null);

 

diff --git a/DotCMIS/client/client-intf.cs b/DotCMIS/client/client-intf.cs
index eb61697..31e935f 100644
--- a/DotCMIS/client/client-intf.cs
+++ b/DotCMIS/client/client-intf.cs
@@ -173,8 +173,31 @@
         IFolder GetRootFolder(IOperationContext context);

         IItemEnumerable<IDocument> GetCheckedOutDocs();

         IItemEnumerable<IDocument> GetCheckedOutDocs(IOperationContext context);

+

+        /// <summary>

+        /// Gets a CMIS object from the session cache. If the object is not in the cache or the cache is 

+        /// turned off per default <see cref="DotCMIS.Client.IOperationContext"/>, it will load the object 

+        /// from the repository and puts it into the cache.

+        /// </summary>

+        /// <param name="objectId">the object id</param>

         ICmisObject GetObject(IObjectId objectId);

         ICmisObject GetObject(IObjectId objectId, IOperationContext context);

+

+        /// <summary>

+        /// Gets a CMIS object from the session cache. If the object is not in the cache or the cache is 

+        /// turned off per default <see cref="DotCMIS.Client.IOperationContext"/>, it will load the object 

+        /// from the repository and puts it into the cache.

+        /// </summary>

+        /// <param name="objectId">the object id</param>

+        ICmisObject GetObject(string objectId);

+        ICmisObject GetObject(string objectId, IOperationContext context);

+

+        /// <summary>

+        /// Gets a CMIS object from the session cache. If the object is not in the cache or the cache is 

+        /// turned off per default <see cref="DotCMIS.Client.IOperationContext"/>, it will load the object

+        /// from the repository and puts it into the cache.

+        /// </summary>

+        /// <param name="path">the path to the object</param>

         ICmisObject GetObjectByPath(string path);

         ICmisObject GetObjectByPath(string path, IOperationContext context);

 

diff --git a/DotCMIS/const.cs b/DotCMIS/const.cs
index 1f09da3..2c70fa2 100644
--- a/DotCMIS/const.cs
+++ b/DotCMIS/const.cs
@@ -50,6 +50,8 @@
         public const string WebServicesPolicyService = "org.apache.chemistry.dotcmis.binding.webservices.PolicyService";

         public const string WebServicesAclService = "org.apache.chemistry.dotcmis.binding.webservices.ACLService";

 

+        public const string WebServicesWCFBinding = "org.apache.chemistry.dotcmis.binding.webservices.wcfbinding";

+

         // authentication provider

         public const string AuthenticationProviderClass = "org.apache.chemistry.dotcmis.binding.auth.classname";