Viewing XML output from C# - 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();

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();

UPS Rating API C# .Net

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" };

QBO IPP API - how to link a payment to an invoice

I am able to successfully create an invoice, and a payment, but don't seem to be able to properly link the payment to the invoice. I have tried several variations, but it either does not link at all, or I get a "Business Validation Error: Unexpected Internal Error." error in my error logs. Below is my c# code. Is there a simplified way (example) of linking a payment to an invoice?
Invoice i = QBGet_InvoiceByMDVInvoiceNum(MDVInvoiceNum);
Payment p = new Payment();
Customer customer = QBGet_CustomerByName(ClientName, "CompanyName");
Account acc = QBGet_AccountsReceivableAccount();
p.TxnDate = DateTime.Now;
p.TxnDateSpecified = true;
List<Line> lineList1 = new List<Line>();
Line pmtLine = new Line();
pmtLine.Amount = ReceivedPaymentAmt;
pmtLine.AmountSpecified = true;
List<LinkedTxn> linkedTxnList = new List<LinkedTxn>();
LinkedTxn linkedtxn = new LinkedTxn();
linkedtxn.TxnId = i.Id;
linkedtxn.TxnType = "invoice";
linkedTxnList.Add(linkedtxn);
pmtLine.LinkedTxn = linkedTxnList.ToArray();
//p.LinkedTxn = linkedTxnList.ToArray();
lineList1.Add(pmtLine);
p.Line = lineList1.ToArray();
p.CustomerRef = new ReferenceType()
{
Value = customer.Id
};
p.DepositToAccountRef = new ReferenceType() { Value = acc.Id };
p.PaymentRefNum = ReceiptCheckNo;
p.TotalAmt = ReceivedPaymentAmt;
p.TotalAmtSpecified = true;
DataService service = new DataService(context);
var result = service.Add<Payment>(p);
I have also tried this approach:
p.CustomerRef = new ReferenceType()
{
Value = customer.Id
};
p.PrivateNote ="ReferralID: " + ReferralId + "\r\n" + "PaymentDetailID: " + PaymentDetailID + "\r\n" + Comments;
p.PaymentRefNum = ReceiptCheckNo;
p.PaymentType = PaymentTypeEnum.Check;
p.PaymentTypeSpecified = true;
p.DocNumber = MDVInvoiceNum;
p.TotalAmt = ReceivedPaymentAmt;
p.TotalAmtSpecified = true;
p.TxnDate = PaymentReceivedDate;
p.TxnDateSpecified = true;
LinkedTxn[] lt = {new LinkedTxn()
{
TxnId=i.Id,
TxnType="invoice"
}
};
Line l = new Line()
{
Amount = ReceivedPaymentAmt,
LinkedTxn = lt
};
Line[] aryL = {l};
DataService service = new DataService(context);
Payment pmt = service.Add(p);
p.Line = aryL;
p.LinkedTxn = lt;
Payment pmt2 = service.Update(p);
Sharing the Java code and corresponding working JSON payload. It might help.
private void paymentAgainstInvoice() {
Payment payment = new Payment();
Date currentDateTime = null;
try {
currentDateTime = DateUtils.getCurrentDateTime();
} catch (ParseException e) {
e.printStackTrace();
}
payment.setTxnDate(currentDateTime);
Line line = new Line();
line.setAmount(new BigDecimal("100"));
LinkedTxn linkedTxn = new LinkedTxn();
linkedTxn.setTxnId("248");
linkedTxn.setTxnType("Invoice");
List<LinkedTxn> linkedTxnList = new ArrayList<LinkedTxn>();
linkedTxnList.add(linkedTxn);
line.setLinkedTxn(linkedTxnList);
List<Line> lineList = new ArrayList<Line>();
lineList.add(line);
payment.setLine(lineList);
ReferenceType custReferenceType = new ReferenceType();
custReferenceType.setValue("29");
custReferenceType.setName("ABC");
payment.setCustomerRef(custReferenceType);
payment.setTotalAmt(new BigDecimal("100"));
ReferenceType accountRefType = new ReferenceType();
accountRefType.setValue("63");
payment.setPaymentRefNum("ABC-100-Invoice");
payment.setDepositToAccountRef(accountRefType );
try {
this.service.add(payment);
} catch (FMSException e) {
e.printStackTrace();
}
}
JSON payload ( Payment )
{
"CustomerRef":{
"value":"29",
"name":"ABC"
},
"DepositToAccountRef":{
"value":"63"
},
"PaymentRefNum":"ABC-100-Invoice",
"TotalAmt":100,
"TxnDate":"2014-11-30",
"Line":[
{
"Amount":100,
"LinkedTxn":[
{
"TxnId":"248",
"TxnType":"Invoice"
}
]
}
]
}

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