Example #1
0
        public RmReference Create(RmGeneric newResource)
        {
            if (newResource == null)
            {
                throw new ArgumentNullException("newResource");
            }

            Message msgRequest  = requestFactory.CreateCreateRequest(newResource);
            Message msgResponse = wsResourceFactoryClient.Create(msgRequest);

            if (msgResponse.IsFault)
            {
                ClientHelper.HandleFault(msgResponse);
            }

            ResponseCreate createResponse = responseFactory.CreateCreateResponse(msgResponse);

            try
            {
                RmReference reference = new RmReference(createResponse.ResourceCreated.EndpointReference.ReferenceProperties.ResourceReferenceProperty.Value);
                if (newResource.ContainsKey(new RmAttributeName(RmResource.AttributeNames.ObjectID.Name)))
                {
                    newResource[RmResource.AttributeNames.ObjectID.Name].Value = reference;
                }
                return(reference);
            }
            catch (NullReferenceException)
            {
                return(new RmReference());
            }
            catch (FormatException)
            {
                return(new RmReference());
            }
        }