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.
CascadingPicklistService service = new CascadingPicklistService();
UsernameToken userToken = new UsernameToken(username, password, PasswordOption.SendPlainText);
CascadingPicklistRead_Input input = new CascadingPicklistRead_Input();
CascadingPicklistRead_Output output;
service.RequestSoapContext.Security.Tokens.Add(userToken);
input.CascadingPicklistSet = new CascadingPicklistSetQuery();
input.CascadingPicklistSet.ObjectName = "Service Request";
output = service.CascadingPicklistRead(input);
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
{
}
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