Ok, I know that your last post was a few months ago, but if you were still working on this (or for people like me who would like to see the answer to this question), here is some information about the NullReferenceException you came up with creating OAuth request:
The null reference comes from IServiceLocator , which is used to resolve dependencies. Unless you explicitly pass one to the constructor, it uses the static ServiceLocator.Current property in the Microsoft.Practices.ServiceLocation namespace.
This is one of the many problems with using static methods and global state; you hide such problems from the consumer of your API. Therefore, if you did not specify a default service locator, null returned, resulting in a NullReferenceException .
So, to fix this problem, I hooked up an IServiceLocator implementation that uses StructureMap (one of the many IoC containers available) as a container. Finally, you will need to register instances for two interfaces: ISigningProvider and INonceProvider . Fortunately, the OAuth.Net.Components assembly has several standard implementations, such as GuidNonceProvider and HmacSha1SigningProvider.
The resulting code looks something like this:
var container = new Container(); container.Configure(a => a.For<INonceProvider>().Use<GuidNonceProvider>()); container.Configure(a => a.For<ISigningProvider>() .Use<HmacSha1SigningProvider>() .Named("signing.provider:HMAC-SHA1")); var locator = new StructureMapAdapter(container); ServiceLocator.SetLocatorProvider(delegate { return locator; });
I understand that this is not the final solution to your initial question (I am still working to get it to work on my own), but I hope these are a few more steps. And if you have long abandoned this implementation ... well, a happy encoding anyway!
jeremyalan
source share