After a week or so of shouting, screaming and hair pulling I've finally managed to get my prototype app to connect to the new NeSS Data Exchange beta program using C# 2008 Express Edition.
It's been a huge pain in the arse because it uses SOAP and security token extensions that aren't supported natively in the Express editions. To make it work properly I had to download and install Microsoft's Web Services Enhancements 3.0. Once installed I had to use the configuration tool to create a wse3policyCache.config file to use a Username token with my application.
Once configured the following code worked a treat:
//Set up Credentials
const String UserName = "username";
const String PassWord = "password";
//Create new token
UsernameToken tkn = new UsernameToken(UserName, PassWord, PasswordOption.SendPlainText);
//Set up containers and service
NeSSDiscoveryService service = new NeSSDiscoveryService();
SubjectTreeRequest theRequest = new SubjectTreeRequest();
//Add token to service
service.RequestSoapContext.Security.Tokens.Add(tkn);
//Perform the query
SubjectTreeResponse theResponse = service.GetSubjectTree(theRequest);
//Get Array length
int responseLength = theResponse.SubjectTree.Length;
//Create Subject Branch Array
SubjectBranch[] theBranches = theResponse.SubjectTree;
//Introduce program
Console.WriteLine("This Program Will test the NeSS Web Services");
//Iterate through results
for (int i = 0; i < responseLength; i++)
{
Console.WriteLine(theBranches[i].Subject.Name);
}
Console.WriteLine();
Console.WriteLine("===========================================");
Console.WriteLine("End of output. You can close this window");
Console.WriteLine("===========================================");
System.Threading.Thread.Sleep(50000);
And hey presto the Subject List is outputted. Now to put that in to practice with a proper app. :)
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment