UPS Rating API C# .Net - c#

I am trying to get the UPS Rating API that now supports Time In Transit to work. I have the latest WSDL (UPS API). I keep getting an exception error "An exception has been raised as a result of client data." and I can not figure out what is the problem. Note: The "Rate" requestOption works with no issues - when TimeinTransit and DeliveryInformation data is commented out.
What could be wrong? Any help would be appreciated, thank you.
Here is my C# code:
UPSRateWS.RequestType request = new UPSRateWS.RequestType();
String[] requestOption = { "ratetimeintransit" };
request.RequestOption = requestOption;
request.SubVersion = "1601";
rateRequest.Request = request;
UPSRateWS.ShipmentType shipment = new UPSRateWS.ShipmentType();
UPSRateWS.ShipperType shipper = new UPSRateWS.ShipperType();
UPSRateWS.ShipmentRatingOptionsType shipmentRatingOptions = new
UPSRateWS.ShipmentRatingOptionsType();
shipmentRatingOptions.NegotiatedRatesIndicator = "";
shipmentRatingOptions.RateChartIndicator = "";
shipment.ShipmentRatingOptions = shipmentRatingOptions;
UPSRateWS.TimeInTransitRequestType timeInTransit = new
UPSRateWS.TimeInTransitRequestType();
UPSRateWS.PickupType pickupInTransitType = new UPSRateWS.PickupType();
pickupInTransitType.Date = "20170414";
pickupInTransitType.Time = "1630";
timeInTransit.Pickup = pickupInTransitType;
timeInTransit.PackageBillType = "02";
shipment.NumOfPieces = "1";
shipment.DeliveryTimeInformation = timeInTransit;
UPSRateWS.ShipmentWeightType shipWeightType = new
UPSRateWS.ShipmentWeightType();
shipWeightType.Weight = "10.80";
UPSRateWS.CodeDescriptionType shipWeightUOM = new
UPSRateWS.CodeDescriptionType();
shipWeightUOM.Code = "LBS";
shipWeightUOM.Description = "pounds";
shipWeightType.UnitOfMeasurement = shipWeightUOM;
shipment.ShipmentTotalWeight = shipWeightType;
shipper.ShipperNumber = "XXXXXX";
UPSRateWS.AddressType shipperAddress = new UPSRateWS.AddressType();
string testAddr = "7650 Tyler Blvd";
String[] addressLine = { testAddr };
shipperAddress.AddressLine = addressLine;
shipperAddress.City = "Mentor";
shipperAddress.PostalCode = "44060";
shipperAddress.StateProvinceCode = "OH";
shipperAddress.CountryCode = "US";
shipperAddress.AddressLine = addressLine;
shipper.Address = shipperAddress;
shipment.Shipper = shipper;
UPSRateWS.ShipFromType shipFrom = new UPSRateWS.ShipFromType();
UPSRateWS.ShipAddressType shipFromAddress = new UPSRateWS.ShipAddressType();
string testAddr2 = "";
String[] addressLine1 = { testAddr2 };
shipFromAddress.AddressLine = addressLine1;
shipFromAddress.City = "";
shipFromAddress.PostalCode = "45069";
shipFromAddress.StateProvinceCode = "OH";
shipFromAddress.CountryCode = "US";
shipFrom.Address = shipFromAddress;
shipment.ShipFrom = shipFrom;
UPSRateWS.ShipToType shipTo = new UPSRateWS.ShipToType();
UPSRateWS.ShipToAddressType shipToAddress = new UPSRateWS.ShipToAddressType();
string testAddr3 = "7650 Tyler Blvd";
String[] addressLine2 = { testAddr3 };
shipToAddress.AddressLine = addressLine2;
shipToAddress.City = "Mentor";
shipToAddress.PostalCode = "44060";
shipToAddress.StateProvinceCode = "OH";
shipToAddress.CountryCode = "US";
shipToAddress.ResidentialAddressIndicator = "1";
shipTo.Address = shipToAddress;
shipment.ShipTo = shipTo;
UPSRateWS.CodeDescriptionType service = new UPSRateWS.CodeDescriptionType();
service.Code = "03";
shipment.Service = service;
UPSRateWS.PackageType package = new UPSRateWS.PackageType();
UPSRateWS.PackageWeightType packageWeight = new UPSRateWS.PackageWeightType();
packageWeight.Weight = "10.80";
UPSRateWS.CodeDescriptionType uom = new UPSRateWS.CodeDescriptionType();
uom.Code = "LBS";
uom.Description = "pounds";
packageWeight.UnitOfMeasurement = uom;
package.PackageWeight = packageWeight;
UPSRateWS.CodeDescriptionType packType = new UPSRateWS.CodeDescriptionType();
packType.Code = "02";
package.PackagingType = packType;
UPSRateWS.PackageServiceOptionsType packServType = new
UPSRateWS.PackageServiceOptionsType();
UPSRateWS.InsuredValueType insuredValueType = new UPSRateWS.InsuredValueType();
insuredValueType.CurrencyCode = "USD";
insuredValueType.MonetaryValue = "65.75";
packServType.DeclaredValue = insuredValueType;
UPSRateWS.ShipperDeclaredValueType shipperDeclaredValueType = new
UPSRateWS.ShipperDeclaredValueType();
shipperDeclaredValueType.CurrencyCode = "USD";
shipperDeclaredValueType.MonetaryValue = "65.75";
packServType.ShipperDeclaredValue = shipperDeclaredValueType;
package.PackageServiceOptions = packServType;
UPSRateWS.PackageType[] pkgArray = { package };
shipment.Package = pkgArray;
rateRequest.Shipment = shipment;
UPSRateWS.CodeDescriptionType pickupType = new UPSRateWS.CodeDescriptionType();
pickupType.Code = "01";
pickupType.Description = "Daily Pickup";
rateRequest.PickupType = pickupType;
UPSRateWS.RateResponse rateResponse = myRatePortTypeClient.ProcessRate(upss,
rateRequest);

You need to include both the "rate" option and the "ratetimeintransit" options:
String[] requestOption = { "rate","ratetimeintransit" };

Related

requests[0]' (oneof), oneof field 'kind' is already set. Cannot set 'updateCell encountered when generating checkbox

I'm trying to generate a checkbox from C#.net using google sheets API but I'm encountering the oneof field kind is already set error. I tried combining extendedValue and DataValidation. Please see code snippet below:
ConditionValue conditionValueTrue = new ConditionValue();
conditionValueTrue.UserEnteredValue = "TRUE";
ConditionValue conditionValueFalse = new ConditionValue();
conditionValueFalse.UserEnteredValue = "FALSE";
ConditionValue[] validValues = { conditionValueTrue, conditionValueFalse };
BooleanCondition bc = new BooleanCondition();
bc.Type = "BOOLEAN";
bc.Values = validValues;
DataValidationRule dataValidationRule = new DataValidationRule();
dataValidationRule.Condition = bc;
dataValidationRule.ShowCustomUi = true;
GridRange validationRange = new GridRange();
validationRange.StartColumnIndex = 7;
validationRange.EndColumnIndex = 7;
validationRange.SheetId = 0;
SetDataValidationRequest setDataValidationRequest = new SetDataValidationRequest();
setDataValidationRequest.Rule = dataValidationRule;
setDataValidationRequest.Range = validationRange;
ExtendedValue extendedValue = new ExtendedValue();
extendedValue.BoolValue = true;
BatchUpdateSpreadsheetRequest busr = new BatchUpdateSpreadsheetRequest();
busr.Requests = new List<Request>();
Request r = new Request();
busr.Requests.Add(r);
r.UpdateCells = new UpdateCellsRequest();
r.SetDataValidation = setDataValidationRequest;
var gc = new GridCoordinate();
gc.ColumnIndex = 7;
gc.RowIndex = row;
gc.SheetId = 0;
r.UpdateCells.Start = gc;
r.UpdateCells.Fields = "*";
r.UpdateCells.Rows = new List<RowData>();
var rd = new RowData();
r.UpdateCells.Rows.Add(rd);
rd.Values = new List<CellData>();
var cd = new CellData();
cd.UserEnteredValue = extendedValue;
rd.Values.Add(cd);
SpreadsheetsResource.BatchUpdateRequest bur = _sheetsService.Spreadsheets.BatchUpdate(busr, SpreadsheetId);
bur.Execute();

Viewing XML output from C#

I'm trying to work with the UPS api to create a shipping label. The UPS api uses a webservice to send an XML request to UPS. UPS then sends a response back. Here is my question.
Is there a way to view the XML that is outputted when I call the "shipmentRequest" method?
This is the first time I've used an API and a webservice so if you need me to provide more information just let me know.
Thanks!
EDIT: Here is my C# code
ShipService shpSvc = new ShipService();
ShipmentRequest shipmentRequest = new ShipmentRequest();
UPSSecurity upss = new UPSSecurity();
//shpSvc.Url = "https://onlinetools.ups.com/webservices/Ship";
UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
upssSvcAccessToken.AccessLicenseNumber = apiCode;
upss.ServiceAccessToken = upssSvcAccessToken;
UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
upssUsrNameToken.Username = userName;
upssUsrNameToken.Password = password;
upss.UsernameToken = upssUsrNameToken;
shpSvc.UPSSecurityValue = upss;
RequestType request = new RequestType();
String[] requestOption = { "nonvalidate" };
request.RequestOption = requestOption;
shipmentRequest.Request = request;
ShipmentType shipment = new ShipmentType();
shipment.Description = "Ship webservice example";
ShipperType shipper = new ShipperType();
shipper.ShipperNumber = accountNumber;
PaymentInfoType paymentInfo = new PaymentInfoType();
ShipmentChargeType shpmentCharge = new ShipmentChargeType();
BillShipperType billShipper = new BillShipperType();
billShipper.AccountNumber = accountNumber;
shpmentCharge.BillShipper = billShipper;
shpmentCharge.Type = "01";
ShipmentChargeType[] shpmentChargeArray = { shpmentCharge };
paymentInfo.ShipmentCharge = shpmentChargeArray;
shipment.PaymentInformation = paymentInfo;
ShipWSSample.ShipWebReference.ShipAddressType shipperAddress = new ShipWSSample.ShipWebReference.ShipAddressType();
String[] addressLine = { "480 Parkton Plaza" };
shipperAddress.AddressLine = addressLine;
shipperAddress.City = "Timonium";
shipperAddress.PostalCode = "21093";
shipperAddress.StateProvinceCode = "MD";
shipperAddress.CountryCode = "US";
shipperAddress.AddressLine = addressLine;
shipper.Address = shipperAddress;
shipper.Name = "ABC Associates";
shipper.AttentionName = "ABC Associates";
ShipPhoneType shipperPhone = new ShipPhoneType();
shipperPhone.Number = "1234567890";
shipper.Phone = shipperPhone;
shipment.Shipper = shipper;
ShipFromType shipFrom = new ShipFromType();
ShipWSSample.ShipWebReference.ShipAddressType shipFromAddress = new ShipWSSample.ShipWebReference.ShipAddressType();
String[] shipFromAddressLine = { "Ship From Street" };
shipFromAddress.AddressLine = addressLine;
shipFromAddress.City = "Timonium";
shipFromAddress.PostalCode = "21093";
shipFromAddress.StateProvinceCode = "MD";
shipFromAddress.CountryCode = "US";
shipFrom.Address = shipFromAddress;
shipFrom.AttentionName = "Mr.ABC";
shipFrom.Name = "ABC Associates";
shipment.ShipFrom = shipFrom;
ShipToType shipTo = new ShipToType();
ShipToAddressType shipToAddress = new ShipToAddressType();
String[] addressLine1 = { "Some Street" };
shipToAddress.AddressLine = addressLine1;
shipToAddress.City = "Roswell";
shipToAddress.PostalCode = "30076";
shipToAddress.StateProvinceCode = "GA";
shipToAddress.CountryCode = "US";
shipTo.Address = shipToAddress;
shipTo.AttentionName = "DEF";
shipTo.Name = "DEF Associates";
ShipPhoneType shipToPhone = new ShipPhoneType();
shipToPhone.Number = "1234567890";
shipTo.Phone = shipToPhone;
shipment.ShipTo = shipTo;
ServiceType service = new ServiceType();
service.Code = "01";
shipment.Service = service;
PackageType package = new PackageType();
PackageWeightType packageWeight = new PackageWeightType();
packageWeight.Weight = "1";
ShipUnitOfMeasurementType uom = new ShipUnitOfMeasurementType();
uom.Code = "LBS";
packageWeight.UnitOfMeasurement = uom;
package.PackageWeight = packageWeight;
PackagingType packType = new PackagingType();
packType.Code = "02";
package.Packaging = packType;
PackageType[] pkgArray = { package };
shipment.Package = pkgArray;
LabelSpecificationType labelSpec = new LabelSpecificationType();
LabelStockSizeType labelStockSize = new LabelStockSizeType();
labelStockSize.Height = "6";
labelStockSize.Width = "4";
labelSpec.LabelStockSize = labelStockSize;
LabelImageFormatType labelImageFormat = new LabelImageFormatType();
labelImageFormat.Code = "SPL";
labelSpec.LabelImageFormat = labelImageFormat;
shipmentRequest.LabelSpecification = labelSpec;
shipmentRequest.Shipment = shipment;
ShipmentResponse shipmentResponse = shpSvc.ProcessShipment(shipmentRequest);
MessageBox.Show("The transaction was a " + shipmentResponse.Response.ResponseStatus.Description);
MessageBox.Show("The 1Z number of the new shipment is " + shipmentResponse.ShipmentResults.ShipmentIdentificationNumber);
You can inherit from the UPS service and read the response as xml by providing your own XmlWriter by overriding GetWriterForMessage(). You can see a working example here.
i am using this code display xml it may help you.
XDocument mySourceDoc = new XDocument();
mySourceDoc = XDocument.Load(shipmentResponse);
txtxml.Text = mySourceDoc.ToString();

Maximo Query Web Service

Does anyone know how I can process Maximo response from a Maximo Query web service ?
I'm able to get a dataset response back from Maximo, however when I try and get the work order attributes (example WONUM, SITEID etc...), all attributes are returned as null.
Below is the code I'm using, any help is appreciated.
MXWO_WORKORDERType wo_add = new MXWO_WORKORDERType();
MXWO_WORKORDERType[] wo_results;
DateTime creationDateTime = new DateTime();
bool creationDateTimeSpecified = false;
string language = "NoDef";
string transLanguage = "NoDef";
string messageID = "NoDef";
string maximoVersion = "NoDef";
bool uniqueResult = false;
string maxItems = "10000";
string rsStart = "0";
string rsCount = "NoDef";
string rsTotal = "NoDef";
MXStringType mxstringStID = new MXStringType();
MXStringType mxstringstatus = new MXStringType();
MXStringType mxstringwonum = new MXStringType();
// create query from string
MXWOQueryType query = new MXWOQueryType();
query.WHERE = ("SITEID = 'ABC' AND STATUS='WAPPR'");
MXWOPortTypeClient c = new MXWOPortTypeClient("MXWOSOAP1Port");
// perform query
MXWO_WORKORDERType[] returnedWOs = c.QueryMXWO(query, ref creationDateTime, ref language, ref transLanguage, ref messageID, ref maximoVersion, uniqueResult, maxItems, ref rsStart, out rsCount, out rsTotal);
MXWO_WORKORDERType wo = null;
for (int i = 0; i < returnedWOs.Length; i++)
{
mxstringwonum.Value = returnedWOs[i].WONUM.Value;
wo.WONUM = mxstringwonum;
MessageBox.Show(mxstringwonum.Value);
}
Check this
MXWO proxy = new MXWO();
MXWO_WORKORDERType[] wo_results;
MXWO_WORKORDERType[] wo_new = new MXWO_WORKORDERType[1];
DateTime creationDateTime = new DateTime();
WebServiceUseCases.com.cts.ctsinpunvemscoe_MXWO.MXStringQueryType[] queryName = new com.cts.ctsinpunvemscoe_MXWO.MXStringQueryType[1];
queryName[0] = new com.cts.ctsinpunvemscoe_MXWO.MXStringQueryType();
queryName[0].Value = "";
WebServiceUseCases.com.cts.ctsinpunvemscoe_MXWO.MXDomainQueryType[] queryStatus = new com.cts.ctsinpunvemscoe_MXWO.MXDomainQueryType[1];
queryStatus[0] = new com.cts.ctsinpunvemscoe_MXWO.MXDomainQueryType();
queryStatus[0].Value = "";
MXWOQueryType query = new MXWOQueryType();
query.WORKORDER = new MXWOQueryTypeWORKORDER();
if (txtBoxWOName.Text != "")
{
queryName[0].Value = txtBoxWOName.Text;
query.WORKORDER.WONUM = queryName;
}
if (cmBoxStatus.SelectedIndex != 0)
{
queryStatus[0].Value = cmBoxStatus.SelectedItem.ToString();
query.WORKORDER.STATUS = queryStatus;
}
proxy.Url = "http://<server name>:<port>/meaweb/services/MXWO";
bool creationDateTimeSpecified = false;
string language = "en";
string transLanguage = "en";
string messageID = "NoDef";
string maximoVersion = "NoDef";
bool uniqueResult = false;
string maxItems = "2000";
string rsStart = "0";
string rsCount = "NoDef";
string rsTotal = "NoDef";
wo_results = proxy.QueryMXWO(query, ref creationDateTime, ref creationDateTimeSpecified, ref language,
ref transLanguage, ref messageID, ref maximoVersion, uniqueResult, maxItems, ref rsStart, out rsCount, out rsTotal);
Thanks Shreyuth. I tweaked your code and code from other articles and got it working. Below is the final code. Thanks for your response/help.
DateTime creationDateTime = new DateTime();
bool creationDateTimeSpecified = false;
string language = "NoDef";
string transLanguage = "NoDef";
string messageID = "NoDef";
string maximoVersion = "NoDef";
bool uniqueResult = false;
string maxItems = "10000";
string rsStart = "0";
string rsCount = "NoDef";
string rsTotal = "NoDef";
MXStringType mxstringStID = new MXStringType();
MXStringType mxstringwonum = new MXStringType();
MXStringType mxDescription = new MXStringType();
Uri serviceUri = new Uri("http://maximourl/meaweb/services/testservice");
BasicHttpBinding serviceBinding = new BasicHttpBinding();
EndpointAddress EndPoint = new EndpointAddress(serviceUri);
ChannelFactory<MXWOPortTypeChannel> channelFactory = new ChannelFactory<MXWOPortTypeChannel>(serviceBinding, EndPoint);
//Create a channel
MXWOPortTypeChannel channel = channelFactory.CreateChannel();
channel.Open();
MXWOQueryType query1 = new MXWOQueryType();
query1.WHERE = ("SITEID = 'ABC' AND STATUS='APPR'");
QueryMXWOResponse resp1 = new QueryMXWOResponse();
QueryMXWORequest creq = new QueryMXWORequest();
creq.baseLanguage = language;
//creq.creationDateTime = creationDateTime;
creq.maximoVersion = maximoVersion;
creq.transLanguage = transLanguage;
creq.messageID = messageID;
creq.rsStart = rsStart;
creq.maxItems = maxItems;
creq.uniqueResult = uniqueResult;
creq.MXWOQuery = query1;
resp1 = channel.QueryMXWO(creq);
MXWO_WORKORDERType[] results = resp1.MXWOSet;
for (int i = 0; i < results.Length; i++)
{
MXWO_WORKORDERType wt = results[i];
mxstringwonum.Value = results[i].WONUM.Value;
wt.WONUM.Value = mxstringwonum.Value;
mxDescription.Value = results[i].DESCRIPTION.Value;
wt.DESCRIPTION.Value = mxDescription.Value;
mxstringStID.Value = results[i].SITEID.Value;
wt.SITEID.Value = mxstringStID.Value;
MessageBox.Show(mxstringStID.Value + " -- " + mxstringwonum.Value + " -- " + mxDescription.Value);
}

Expedia hotel API

I am working on Expedia hotel API.All the function are working except booking.All the other request using GET method for requesting.But in booking we have to use the POST method with different URL.So i changed the URL for request but still getting the error.
My codes are
HotelServicesImplService client = new HotelServicesImplService();
HotelRoomReservationRequest bookreq = new HotelRoomReservationRequest();
HotelRoomReservationResponse bookres = new HotelRoomReservationResponse();
addressInfo bookad = new addressInfo();
reservationInfo bookinfo = new reservationInfo();
client.Url = "https://book.api.ean.com/ean-services/rs/hotel/v3";
//bookreq.minorRevSpecified = true;
//bookreq.minorRev = 25;
bookreq.hotelId = 106347;
bookreq.apiKey = "api";
bookreq.cid = "cid";
bookreq.arrivalDate = "12/11/2013";
bookreq.departureDate = "12/13/2013";
bookreq.supplierType = SupplierType.E;
bookreq.rateKey = "af00b688-acf4-409e-8bdc-fcfc3d1cb80c";
bookreq.roomTypeCode = "198058";
bookreq.rateCode = "484072";
bookreq.RoomGroup = new[] { new Room
{
numberOfAdults=Convert.ToInt32(2),
numberOfChildren=Convert.ToInt32(0),
childAges=new int[] {} ,
firstName="Test Booking",
lastName="Test Booking",
bedTypeId="23",
smokingPreference=SmokingPreference.NS,
}};
float i = float.Parse("231.18");
bookreq.currencyCode = "USD";
bookreq.chargeableRate = i;
bookinfo.email = "ranaabhi007#yahoo.com";
bookinfo.firstName = "TestBooking";
bookinfo.lastName = "TestBooking";
bookinfo.homePhone = "2145370159";
bookinfo.workPhone = "2145370159";
bookinfo.creditCardType = "CA";
bookinfo.creditCardNumber = "5401999999999999";
bookinfo.creditCardIdentifier = "TestBooking";
bookinfo.creditCardExpirationMonth = "12";
bookinfo.creditCardExpirationYear = "2015";
bookad.city = "Seattle";
bookad.stateProvinceCode = "WA";
bookad.countryCode = "US";
bookad.postalCode = "98004";
bookreq.ReservationInfo = bookinfo;
bookad.address1 = "travelnow";
//bookad.city = txtCity.Text;
//bookad.stateProvinceCode = txtState.Text;
//bookad.countryCode = txtCountry.Text;
//bookad.postalCode = txtPostal.Text;
bookreq.AddressInfo = bookad;
bookres = client.getReservation(bookreq);
// HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(client);
Response.Write(bookres.confirmationNumbers);
Response.Write(bookres.departureDate);
Response.Write(bookres.drivingDirections);
Response.Write(bookres.CouponInformationResponse);
but i am still getting the error
The request failed with HTTP status 404: Not Found.
Are you sure your URL is correct? According to the documentation, it should be
https://book.api.ean.com/ean-services/rs/hotel/v3/res

How does one successfully call createDocument through the Sharepoint CMIS connector webservice?

I'm getting the following error:
One or more of the input parameters to the service method is missing or invalid.
when
ObjectService.createDocument(repositoryId, objectPropertyCollection, rootFolderId, myContentStream, ObjectService.enumVersioningState.none, null, addAclcontrol, null, ref extType);
is called. This is how I have setup all of those parameters:
//Get repositoryId, and rootFolder id.
string repositoryId = RepositoryStore[contentType];
RepositoryService.cmisRepositoryInfoType repoInfo =_controller.RepositoryClient.getRepositoryInfo(repositoryId, new RepositoryService.cmisExtensionType());
string rootFolder = repoInfo.rootFolderId;
string theActualName = filename.Substring(filename.LastIndexOf("\\") + 1);
//Create a cmisContentStreamType.
ObjectService.cmisContentStreamType fileStream = new ObjectService.cmisContentStreamType();
fileStream.stream = File.ReadAllBytes(filename);
fileStream.filename = theActualName;
fileStream.length = fileStream.stream.Length.ToString();
fileStream.mimeType = "application/pdf";
//Setting the acl objects needed to create the document.
ObjectService.cmisAccessControlEntryType homeMembers = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType owners = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType viewers = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType visitors = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlPrincipalType ownersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
ownersPrincipalType.principalId = #"Home Owners";
owners.principal = ownersPrincipalType;
owners.permission = new string[] { "cmis:all" };
ObjectService.cmisAccessControlPrincipalType homePrincipalType = new ObjectService.cmisAccessControlPrincipalType();
homePrincipalType.principalId = #"Home Members";
homeMembers.principal = homePrincipalType;
homeMembers.permission = new string[] { "cmis:write" };
ObjectService.cmisAccessControlPrincipalType viewersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
homePrincipalType.principalId = #"Viewers";
homeMembers.principal = viewersPrincipalType;
homeMembers.permission = new string[] { "cmis:read" };
ObjectService.cmisAccessControlPrincipalType visitorsPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
homePrincipalType.principalId = #"Home Visitors";
homeMembers.principal = visitorsPrincipalType;
homeMembers.permission = new string[] { "cmis:read" };
ObjectService.cmisAccessControlEntryType[] addAclControl = new ObjectService.cmisAccessControlEntryType[] { homeMembers, owners, viewers, visitors };
ObjectService.cmisExtensionType exttype = new ObjectService.cmisExtensionType();
ObjectService.cmisPropertiesType objectPropertyArray = MakedocumentPropertiesList(theActualName,fileStream.length);
private ObjectService.cmisPropertiesType MakedocumentPropertiesList(string fileName,string contentStreamLength)
{
List<ObjectService.cmisProperty> arrProps = new List<ObjectService.cmisProperty>();
ObjectService.cmisPropertiesType props = new ObjectService.cmisPropertiesType();
arrProps.Add(GetPropertyString("Name", "cmis:name", "mydocuemntname", "FileLeafRef"));
arrProps.Add(GetPropertyId("cmis:baseTypeId", "cmis:baseTypeId", "cmis:document", "cmis:baseTypeId"));
props.Items = arrProps.ToArray();
return props;
}
private ObjectService.cmisPropertyString GetPropertyString(string displayName, string queryName, string value, string localName)
{
ObjectService.cmisPropertyString title = new ObjectService.cmisPropertyString();
title.localName = localName;
title.displayName = displayName;
title.queryName = queryName;
title.propertyDefinitionId = displayName;
title.value = new string[] { value };
return title;
}
private ObjectService.cmisPropertyId GetPropertyId(string displayName, string queryName, string value, string localName)
{
ObjectService.cmisPropertyId id = new ObjectService.cmisPropertyId();
id.localName = localName;
id.displayName = displayName;
id.queryName = queryName;
id.propertyDefinitionId = displayName;
id.value = new string[] { value };
return id;
}
You cannot set the "cmis:baseTypeId" property, but you have to set the "cmis:objectTypeId" property. Try exchanging the id of your second property.
Apart from that, you should have a look at DotCMIS. It could save you a lot of work.
I took your code and I correct it .. now it is functional for me .. take a look :
string user = txtLogin.Text;
string password = txtPwd.Text;
DemoCMISForms.RepositoryService.RepositoryServicePortClient repService = new DemoCMISForms.RepositoryService.RepositoryServicePortClient("BasicHttpBinding_IRepositoryServicePort2");
repService.ClientCredentials.UserName.UserName = user;
repService.ClientCredentials.UserName.Password = password;
DemoCMISForms.ObjectService.ObjectServicePortClient objectService = new DemoCMISForms.ObjectService.ObjectServicePortClient("BasicHttpBinding_IObjectServicePort2");
objectService.ClientCredentials.UserName.UserName = user;
objectService.ClientCredentials.UserName.Password = password;
//Get repositoryId, and rootFolder id.
RepositoryService.cmisRepositoryInfoType repoInfo = repService.getRepositoryInfo(idRep, new RepositoryService.cmisExtensionType());
string rootFolder = repoInfo.rootFolderId;
string theActualName = textBox1.Text.Substring(textBox1.Text.LastIndexOf("\\") + 1);
//Create a cmisContentStreamType.
ObjectService.cmisContentStreamType fileStream = new ObjectService.cmisContentStreamType();
fileStream.stream = File.ReadAllBytes(textBox1.Text);
fileStream.filename = theActualName;
fileStream.length = fileStream.stream.Length.ToString();
fileStream.mimeType = "text/plain";
//Setting the acl objects needed to create the document.
ObjectService.cmisAccessControlEntryType homeMembers = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType owners = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType viewers = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlEntryType visitors = new ObjectService.cmisAccessControlEntryType();
ObjectService.cmisAccessControlPrincipalType ownersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
ownersPrincipalType.principalId = #"Home Owners";
owners.principal = ownersPrincipalType;
owners.permission = new string[] { "cmis:all" };
ObjectService.cmisAccessControlPrincipalType homePrincipalType = new ObjectService.cmisAccessControlPrincipalType();
homePrincipalType.principalId = #"Home Members";
homeMembers.principal = homePrincipalType;
homeMembers.permission = new string[] { "cmis:write" };
ObjectService.cmisAccessControlPrincipalType viewersPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
viewersPrincipalType.principalId = #"Viewers";
viewers.principal = viewersPrincipalType;
viewers.permission = new string[] { "cmis:read" };
ObjectService.cmisAccessControlPrincipalType visitorsPrincipalType = new ObjectService.cmisAccessControlPrincipalType();
visitorsPrincipalType.principalId = #"Home Visitors";
visitors.principal = visitorsPrincipalType;
visitors.permission = new string[] { "cmis:read" };
ObjectService.cmisAccessControlEntryType[] addAclControl = new ObjectService.cmisAccessControlEntryType[] { homeMembers, owners, viewers, visitors };
ObjectService.cmisExtensionType exttype = new ObjectService.cmisExtensionType();
ObjectService.cmisPropertiesType objectPropertyArray = MakedocumentPropertiesList(theActualName, fileStream.length);
objectService.createDocument(idRep, objectPropertyArray, idFolder, fileStream, ObjectService.enumVersioningState.major, null, addAclControl, null, ref exttype);
}
private ObjectService.cmisPropertiesType MakedocumentPropertiesList(string fileName, string contentStreamLength)
{
List<ObjectService.cmisProperty> arrProps = new List<ObjectService.cmisProperty>();
ObjectService.cmisPropertiesType props = new ObjectService.cmisPropertiesType();
arrProps.Add(GetPropertyString(fileName, "cmis:name", fileName, "FileLeafRef"));
arrProps.Add(GetPropertyId("cmis:objectTypeId", "cmis:objectTypeId", "cmis:document", "cmis:objectTypeId"));
props.Items = arrProps.ToArray();
return props;
}
private ObjectService.cmisPropertyString GetPropertyString(string displayName, string queryName, string value, string localName)
{
ObjectService.cmisPropertyString title = new ObjectService.cmisPropertyString();
title.localName = localName;
title.displayName = displayName;
title.queryName = queryName;
title.propertyDefinitionId = displayName;
title.value = new string[] { value };
return title;
}
private ObjectService.cmisPropertyId GetPropertyId(string displayName, string queryName, string value, string localName)
{
ObjectService.cmisPropertyId id = new ObjectService.cmisPropertyId();
id.localName = localName;
id.displayName = displayName;
id.queryName = queryName;
id.propertyDefinitionId = displayName;
id.value = new string[] { value };
return id;
}
I found some variables that were left unchanged after a copy paste manip! I also used this example with a text file !
Hope I helped you!
PS: I didnt handle yet the problem of document types , i just made the example functionnal with Text files.. Also the versionning in the list I'm calling from the SP Site is an issue so i have to verify before I add any document..

Categories