Click here to Skip to main content
Click here to Skip to main content

Adding an http Security Header to Web Reference and Using Oracle CRM Stateless

, 4 Jun 2012
Rate this:
Please Sign up or sign in to vote.
Adding an http security header to web reference and using Oracle CRM stateless

Introduction

When we add a web reference in C#.NET, we don't have access to add a security header. In the case of Oracle CRM, we need to add a security header to do stateless calls.

The usual way would be to specify the service credentials but in the case of Oracle CRM, this does not work. You'll get an error Missing <wsse:Security...

The Solution

First download the Microsoft WEB SERVICES ENHANCEMENTS (WSE 2.0 or 3.0); this DLL will have the namespace that we'll need to add the functionality to the web service reference.

When you add a web reference, Visual Studio will add a reference.cs file that has all the methods available in the service. Open this file and change the inherited object from System.Web.Services.Protocols.SoapHttpClientProtocol to Microsoft.Web.Services3.WebServicesClientProtocol.

By changing the namespace, we can now add a security header and specify the user and password.

//instance of the service
CascadingPicklistService service = new CascadingPicklistService();

//Create the security tocken
UsernameToken userToken = new UsernameToken(username, password, PasswordOption.SendPlainText);

//Input and output parameters
CascadingPicklistRead_Input input = new CascadingPicklistRead_Input();
CascadingPicklistRead_Output output;

//Add the token on the service
service.RequestSoapContext.Security.Tokens.Add(userToken);
input.CascadingPicklistSet = new CascadingPicklistSetQuery();
//Select pick lists for CRM service requests
input.CascadingPicklistSet.ObjectName = "Service Request";
output = service.CascadingPicklistRead(input);

//Select the picklist
List>PicklistValueAssociationsData< lst =
output.ListOfCascadingPicklistSet[0].ListOfCascadingPicklist.Where(prop => 
prop.ParentPicklist == "PickToSelect").
FirstOrDefault().ListOfPicklistValueAssociations.ToList();
PicklistValueAssociationsData listData = 
lst.Where(pp => pp.ParentPicklistValue == parentValue).FirstOrDefault();
if (listData != null)
{
    return listData.RelatedPicklistValue.ToDictionary(a => a, b => b);
}
else
{
    //Not Found, Do your stuff
}

Conclusion

This solution will enable us to add the security header to a reference of a web service. There is one setback with this solution. Every time you update the web reference, you'll need to set the namespace in the reference.cs file. That being said, if you have worked with Oracle CRM and know a better solution to do Stateless calls on C#, let me know.

History

  • 6/4/2012: First draft

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Ismael Almonte

United States United States
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 5 Jun 2012
Article Copyright 2012 by Ismael Almonte
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid