Sharepoint List webservice error on CheckoutFile method with SSL - c#

I am trying to checkout a file from a SharePoint document library before downloading to my client application for edit.
//documentPath = https://192.168.1.10/Utility/Phys/Document%20Library/document.xml
//listWebServiceURL = https://192.168.1.10/Utility/Phys/Document%20Library/_vti_bin/lists.asmx
private void CheckOutFile(string documentPath)
{
string listWebServiceUrl = this.GetListServiceURL(documentPath);
bool checkedOut;
using (Lists listWebService = new Lists())
{
listWebService.Credentials = CredentialCache.DefaultCredentials;
listWebService.Url = listWebServiceUrl;
checkedOut = listWebService.CheckOutFile(documentPath, "true", string.Empty);
}
}
When the checkedOut = listWebService.CheckOutFile(documentPath, "true", string.Empty); line runs I get a SOAPServerException.
((System.Xml.XmlElement)((System.Web.Services.Protocols.SoapException)(ex)).Detail).InnerText
Object reference not set to an instance of an object.
Any help on this would be appreciated.
Thank you,
Keith
EDIT:
I have tested the above code against a SharePoint library that does not use SSL and it seems to work fine.

Maybe this is an alternate access mapping problem (The "Object Not Set" error is a telltale sign)? You've got one for https://192.168.1.10/ in Central Administration->Operations->Global Configuration->Alternate Access Mappings, ya?

I believe you have to provide a time value in the last argument in listWebService.CheckOutFile. It may be complaining about the string.Empty. Try putting in a string like; "12 May 2009 22:00:00 GMT"

I just ran into this Object Reference error and got it to work by adding the domain to the URL.
http://servername - gets an error,
but
http://servername.domain.com - checkout worked
Makes sense that by being fully qualified it's clearly in the intranet zone for alternate access mappings.

Related

How to implement ILastUpdateInfoFactory Ocean 2013?

I'm a newbie on Ocean Schlumberger 2013. I've been trying to use the LastModified Property from Slb.Ocean.Petrel.XXX (Where XXX means Well, VolumeCalculation, etc) but when I use it I get the following warning.
Warning 1 'Slb.Ocean.Petrel.DomainObject.Model.LastModified' is
obsolete: '"Obsolete in 2013.1. Please use ILastUpdateInfoFactory
instead."' C:\Users\XXXX\documents\visual studio
2012\Projects\ListGr\ListGr\ListGrLogs.cs 113 25 ListGr
I already read the ILastUpdateInfoFactory help documentation but I dunno how to implement this on my plugin and obtain a similar result to LastModified property. Can someone give me a hand with this?
Regards.
Don't know if this is what you are looking for, but from the Ocean help file on ILastUpdateInfoFactory:
// Code that gets the LastUpdateInfo from an native or custom domain object
public void GetLastUpdateInfo(object domainObject)
{
// Get the service
ILastUpdateInfoFactory lastUpdateInfoFactory = CoreSystem.GetService<ILastUpdateInfoFactory>(domainObject);
// Get the LastUpdateInfo
LastUpdateInfo lastUpdateInfo = lastUpdateInfoFactory.GetLastUpdateInfo(domainObject);
// Process the result
PetrelLogger.InfoOutputWindow(string.Format("Last updated at: {0} by {1}.",
lastUpdateInfo.Time, lastUpdateInfo.UserName));
}

ActiveDirectory error 0x8000500c when traversing properties

I got the following snippet (SomeName/SomeDomain contains real values in my code)
var entry = new DirectoryEntry("LDAP://CN=SomeName,OU=All Groups,dc=SomeDomain,dc=com");
foreach (object property in entry.Properties)
{
Console.WriteLine(property);
}
It prints OK for the first 21 properties, but then fail with:
COMException {"Unknown error (0x8000500c)"}
at System.DirectoryServices.PropertyValueCollection.PopulateList()
at System.DirectoryServices.PropertyValueCollection..ctor(DirectoryEntry entry, String propertyName)
at System.DirectoryServices.PropertyCollection.PropertyEnumerator.get_Entry()
at System.DirectoryServices.PropertyCollection.PropertyEnumerator.get_Current()
at ActiveDirectory.Tests.IntegrationTests.ObjectFactoryTests.TestMethod1() in MyTests.cs:line 22
Why? How can I prevent it?
Update
It's a custom attribute that fails.
I've tried to use entry.RefreshCache() and entry.RefreshCache(new[]{"theAttributeName"}) before enumerating the properties (which didn't help).
Update2
entry.InvokeGet("theAttributeName") works (and without RefreshCache).
Can someone explain why?
Update3
It works if I supply the FQDN to the item: LDAP://srv00014.ssab.com/CN=SomeName,xxxx
Bounty
I'm looking for an answer which addresses the following:
Why entry.Properties["customAttributeName"] fails with the mentioned exception
Why entry.InvokeGet("customAttributeName") works
The cause of the exception
How to get both working
If one wants to access a custom attribute from a machine that is not
part of the domain where the custom attribute resides (the credentials
of the logged in user don't matter) one needs to pass the fully
qualified name of the object is trying to access otherwise the schema
cache on the client machine is not properly refreshed, nevermind all
the schema.refresh() calls you make
Found here. This sounds like your problem, given the updates made to the question.
Using the Err.exe tool here
http://www.microsoft.com/download/en/details.aspx?id=985
It spits out:
for hex 0x8000500c / decimal -2147463156 :
E_ADS_CANT_CONVERT_DATATYPE adserr.h
The directory datatype cannot be converted to/from a native
DS datatype
1 matches found for "0x8000500c"
Googled "The directory datatype cannot be converted to/from a native" and found this KB:
http://support.microsoft.com/kb/907462
I have the same failure. I´m read and saw a lot of questions about the error 0x8000500c by listing attribute from a DirectoryEntry.
I could see, with the Process Monitor (Sysinternals), that my process has read a schema file. This schema file is saved under
C:\Users\xxxx\AppData\Local\Microsoft\Windows\SchCache\xyz.sch.
Remove this file and the program works fine :)
I just encountered the issue and mine was with a web application.
I had this bit of code which pulls the user out of windows authentication in IIS and pulls their info from AD.
using (var context = new PrincipalContext(ContextType.Domain))
{
var name = UserPrincipal.Current.DisplayName;
var principal = UserPrincipal.FindByIdentity(context, this.user.Identity.Name);
if (principal != null)
{
this.fullName = principal.GivenName + " " + principal.Surname;
}
else
{
this.fullName = string.Empty;
}
}
This worked fine in my tests, but when I published the website it would come up with this error on FindByIdentity call.
I fixed the issue by using correct user for the app-pool of the website. As soon as I fixed that, this started working.
I had the same problem with a custom attribute of a weird data type. I had a utility program that would extract the value, but some more structured code in a service that would not.
The utility was working directly with a SearchResult object, while the service was using a DirectoryEntry.
It distilled out to this.
SearchResult result;
result.Properties[customProp]; // might work for you
result.Properties[customProp][0]; // works for me. see below
using (DirectoryEntry entry = result.GetDirectoryEntry())
{
entry.Properties[customProp]; // fails
entry.InvokeGet(customProp); // fails as well for the weird data
}
My gut feel is that the SearchResult is a little less of an enforcer and returns back whatever it has.
When this is converted to a DirectoryEntry, this code munges the weird data type so that even InvokeGet fails.
My actual extraction code with the extra [0] looks like:
byte[] bytes = (byte[])((result.Properties[customProp][0]));
String customValue = System.Text.Encoding.UTF8.GetString(bytes);
I picked up the second line from another posting on the site.

vmware .net api help vmware.vim.dll problems

Vmware's .net api reference is somewhat confusing and hard to follow. I have been able to connect to my vcenter host then get a list of esxi hosts. Then I have been able get all the running modules on the host using HostKernelModuleSystem, and probe the properties on the variable "mod"... but I am not able to figure out how to get license info, I tried creating an object lic below, trying all different kinds of "types" from vmware with the word license in the type. but, it never works it has a problem converting the line with LicenseManagerLicenseInfo lic = .... I always get the following:
"Cannot convert type 'Vmware.Vim.Viewbase' to
'Vmware.Vim.LicenseManagerLicenseInfo'"
but the declaration above it for "mod" works fine.
I have also tried:
HostLicenseConnectInfo
LicenseAssignmentManagerLicenseAssignment
LicenseManager
I am hoping someone who has worked with vmware .net api can shed some light on what i am doing wrong? I am new to C# about 1 year :) but these VMware APIs are somewhat confusing to me.
esxList = client.FindEntityViews(typeof(HostSystem), null, null, null);
foreach (HostSystem host in esxList)
{
HostKernelModuleSystem mod = (HostKernelModuleSystem)client.GetView(host.ConfigManager.KernelModuleSystem, null);
LicenseManagerLicenseInfo lic = (LicenseManagerLicenseInfo)client.GetView(host.ConfigManager.LicenseManager, null);
string name = lic.Name;
}
I'll have to go to work tomorrow to look at this ( don't have ESX and VMWare SDK for .NET at home ) but I've done a bit of this work.
I wrote a generics method that wraps FindEntityViews and takes a filter as an argument. That makes it easy to search for anything. Also I've noticed that searches come back as ManagedObjectReferences and can't be cast to the subclasses. You have to construct them passing the ManagedObjectReference as an argument.
Also I find searching for PowerCLI examples and watching the classes in the immeadiate window very help in navigating this API. It's a fairly decent SDK but they put all of the classes in a single namespace and there's lots of little style inconsistencies ( Device instead of Devices and properties that take strings instead of enums when an enum exists ).
i figured out how to do it :) , by using http://vcenter_hostname/mob I was able to walk through api better. here is what I did, plus instead of of using "host" which was type HostSystem I jused my instance of my vCenter host "client"
VMware.Vim.LicenseManager lic_manager = (VMware.Vim.LicenseManager)client.GetView(client.ServiceContent.LicenseManager, null);
LicenseManagerLicenseInfo[] lic_found = lic_manager.Licenses;
foreach (LicenseManagerLicenseInfo lic in lic_found)
{
string test = lic.Name.ToString();
string test2 = lic.LicenseKey.ToString();
}

Sharepoint web.config changes using SPWebConfigModification

I've written a sharepoint application that needs to change web.config
I have a feature that is supposed to make all these configurations. The code for that feature is like this:
SPSite site = properties.Feature.Parent as SPSite;
List<SPWebConfigModification> modifications = new List<SPWebConfigModification>();
modifications.AddRange(CustomErrorsModeConfig.Modifications);
webConfigModificationHelper.AddWebConfigModifications(site.WebApplication, modifications);
CustomErrorsModeConfig.Modifications property contains this code:
public static SPWebConfigModification[] Modifications = {
new SPWebConfigModification()
{
Owner = WebConfigModificationOwner,
Name = "mode",
Type = SPWebConfigModification.SPWebConfigModificationType.EnsureAttribute,
Path = "system.web/customErrors",
Sequence = 0,
Value = "Off"
}
};
Then finally the webConfigModificationHelper.AddWebConfigModifications method:
foreach (SPWebConfigModification modification in modifications)
{
webApp.WebConfigModifications.Add(modification);
}
webApp.Farm.Services.GetValue<SPWebService>().ApplyWebConfigModifications();
webApp.Update();
The problem is that I keep getting this error:
Name cannot begin with the ''' character, hexadecimal value 0x27. Line 1, position 1453
Could this be a problem with the web.config before I try to apply my changes ?
Could the SPWebConfigModification property be incorrectly defined ?
Is there some glitch in my code that leads to this error ?
Might there be some property I am missing (e.g. web.AllowUnsafeUpdates) ?
Some sharepoint site configuration ?
I've been trying to solve this issue for some time now with no luck :( Any ideas ?
I can recommend using stsadmwebconfig for making changes to web.config files. I've implemented this in many features and it has always been a pain, especially while developing. Using this tool makes it a lot easier.
Ive seen this before when the file format is not correctly set between the file and the declaration.
Open the web.config file into a advanced text editor (Notepad++ or Visual Studio) and manually force the file type to match what is specified. Usually its going to be UTF-8.
For more info:
http://www.dumpsterdoggy.com/tutorials/?xmlexception-name-cannot-begin-with
Try taking the List template and for loop out and set the property using straightforward syntax. Here's a post for setting the property in your example, see if you can get this to work and then progress to building up a more generic solution with a List and iteration over the items in the list.
http://www.sharepointkings.com/2008/05/how-to-modify-webconfig-file-in.html

Object reference not set to an instance of an object

I usually get this error and (always) don't know how to solve it.
This time I got it also, it seems that I'm not understanding a concept or missing something
Here's the code
// create a new twitteroo core with provided username/password
TwitterooCore core = new TwitterooCore(username, password);
// request friends timeline from twitter
Users users = core.GetTimeline(Timeline.Friends); // error here
Please some help and also some explanations of what's happening
Thanks
This error is a pain, it basically means some vairable you're accessing is still Null.
In this instance, where do you initialise Timeline? Should your code be something like:
Users users = core.GetTimeline().Friends;
OK, I've been looking at the twiteroo documentation, which is a bit sparse, and I think you definitely need to instantiate an instance of Timeline to pass into GetTimeline, (which returns a collections of Users, not very well named IMHO). What I can't figure out is how to initiate an instance of Timeline.
OK, it's not Timeline that's null, (that's an Enum!) so as bthb says, it can only be the core, perhaps the username or password are wrong, or it can't connect to twitter?
I found the problem finally
It was because of my Firewall seems to be blocking connections to Visual Studio.
Now it works with no changes at all :)
Thanks for all your support
It could be core, username, password, or Timeline.Friends, impossible to know which by the info you have given us.
If I were you I'd put a breakpoint on the line that errors, then stick a watch on Timeline.Friends and check its not null, if its not then put a watch on core.GetTimeline(Timeline.Friends) and see if thats returning null.
It should give you a nudge in the right direction, you'll probably have to read the documentation for the twitter API your using to find out why either of these is returning null.
How about checking your code like:
Users users = null;
if (Timeline != null)
{
TwitterooCore core = new TwitterooCore(username, password);
if (core != null)
{
var friends = Timeline.Friends
if (friends != null)
users = core.GetTimeline(Timeline.Friends);
}
}
If this runs without exceptions one of the objects was probably null.
There are two specific phrases in the error message, object reference and instance of an object. These concepts are very basic when dealing with OOP languages.
First, an object reference can be thought of a variable in a function or class. This term may also refer to function parameters that expect a specific reference to an object. Initially the value of a variable is NULL until it is set to a value using the '=' operator. Frequently you will have a variable declaration and the '=' operation in the same statement.
The term instance of an object refers to an object that has been created using the syntax new. When you call new to initialize an object, an unused memory location is allocated to store a copy of the object until the program ends, or the object goes out of scope and is freed by the garbage collector. At creation time the object properties are defined by the constructor method called to create the object.
Consider this code:
Integer my_int;
my_int = new Integer(5);
In this example, 'my_int' is the object reference to an Integer object instance being created.
If you try to access 'my_int', before assigning it a reference to an Integer instance, then you would have the error, "an object reference (my_int) not set to an instance of an object (Integer)".
If you decompile the dll you will see that GetTimeline(Enum) takes in a Enumeration argument.
The Constructor call will be fine:
TwitterooCore core = new TwitterooCore(username, password);
Source:
public TwitterooCore(string username, string password)
{
this._username = username;
this._password = password;
}
GetTimeline is were the connection is attempted.
public Users GetTimeline(Timeline timeline)
{
WebClient client = new WebClient();
XmlDocument document = new XmlDocument();
string xml = string.Empty;
byte[] buffer = null;
client.set_Credentials(this.GetCredentials());
buffer = client.DownloadData(this.GetTimelineUrl(timeline));
xml = Encoding.UTF8.GetString(buffer);
document.LoadXml(xml);
return this.DecodeStatusXml(document);
}
May be Timeline.Friends is null and may be Timeline is null. I suggest you look at the stack trace of exception and into documentation of your twitter framework.

Categories