This website uses cookies. By clicking Accept, you consent to the use of cookies. Click Here to learn more about how we use cookies.
Turn on suggestions
Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.
- Revenera Community
- :
- FlexNet Publisher
- :
- FlexNet Publisher Forum
- :
- Re: Authenticating to web services in C#
Subscribe
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Subscribe
- Mute
- Printer Friendly Page
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Nov 24, 2006
10:19 PM
Authenticating to web services in C#
I've having some issues authenticating to the FlexNet web services in a C# client I'm developing. Here's the code I'm using:
Of course sampleLicense, host, and port all have proper values in the actual code. Anyone have any suggestions?
macroLic.getFulfillmentsQueryRequestType cdpRequest = new global::formpost.macroLic.getFulfillmentsQueryRequestType();
macroLic.getFulfillmentCountRequestType count = new global::formpost.macroLic.getFulfillmentCountRequestType();
macroLic.fulfillmentsQueryParametersType cparams = new global::formpost.macroLic.fulfillmentsQueryParametersType();
string key = "sampleLicense";
macroLic.SimpleQueryType keyQuery = new global::formpost.macroLic.SimpleQueryType();
keyQuery.value = key;
cparams.activationId = keyQuery;
cparams.activationId.searchType = macroLic.simpleSearchType.EQUALS;
cdpRequest.queryParams = cparams;
//count.queryParams = cparams;
count.queryParams = cparams;
macroLic.LicenseService lic = new global::formpost.macroLic.LicenseService();
System.Net.NetworkCredential netCred = new System.Net.NetworkCredential("user", "password");
System.Net.CredentialCache myCred = new System.Net.CredentialCache();
myCred.Add("http://host:port/flexnet/services/LicenseService", 8888, "Basic", netCred);
lic.Credentials = myCred;
lic.PreAuthenticate = true;
lic.Url = "http://host:port/flexnet/services/LicenseService";
macroLic.getFulfillmentCountResponseType response = lic.getFulfillmentCount(count);
if (response.statusInfo.status.HasValue)
{
string r = response.responseData.ToString();
MessageBox.Show(r);
}
Of course sampleLicense, host, and port all have proper values in the actual code. Anyone have any suggestions?
(3) Replies
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Mar 15, 2007
09:15 AM
Hello,
I am encountering the exact same problem. Did you find a solution ?
Regards,
L. LEMAIRE
I am encountering the exact same problem. Did you find a solution ?
Regards,
L. LEMAIRE
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Apr 12, 2007
10:51 AM
Depending on what version of the Publisher you are using. We recently switch from 5.0 to 6.1. We now have issue with authentication. They have blocked this option out if you are not a premier user. Not cool .
- Mark as New
- Subscribe
- Mute
- Permalink
- Report Inappropriate Content
‎Apr 12, 2007
12:12 PM
One way to handle the FLEXnet Operations web-service authentication in a C# client (this example generated with the "Add Web Reference" functionality in Visual Studio 2005) is to add the authentication to the request header; in the generated proxy class (for the ProductPackagingService, in this example), look for this:
And add code similar to this:
[code]protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest request;
request = (HttpWebRequest)base.GetWebRequest(uri);
if (PreAuthenticate)
{
NetworkCredential networkCredentials =
Credentials.GetCredential(uri, "Basic");
if (networkCredentials != null)
{
byte[] credentialBuffer =
new
System.Text.UTF8Encoding( ).GetBytes(
networkCredentials.UserName + ":" +
networkCredentials.Password);
request.Headers["Authorization"] =
"Basic " +
Convert.ToBase64String(credentialBuffer);
}
else
{
throw new ApplicationException(
"No network credentials");
}
}
return request;
}[/code]This overridden function specifies that requests are to use "Basic" HTTP authentication, adding a new "Authorization" header with credentials of the form "Basic " plus the base-64-encoded "Name:Password" string. (You might need to add using System.Net; to the generated class.)
In the client code, then, you can use code similar to the following:
(Regarding comments about versions 5.0 and 6.1: if you're referring to FLEXnet Connect (formerly Update Service), you might consider posting to this forum.)
public partial class ProductPackagingService : ...
And add code similar to this:
[code]protected override WebRequest GetWebRequest(Uri uri)
{
HttpWebRequest request;
request = (HttpWebRequest)base.GetWebRequest(uri);
if (PreAuthenticate)
{
NetworkCredential networkCredentials =
Credentials.GetCredential(uri, "Basic");
if (networkCredentials != null)
{
byte[] credentialBuffer =
new
System.Text.UTF8Encoding( ).GetBytes(
networkCredentials.UserName + ":" +
networkCredentials.Password);
request.Headers["Authorization"] =
"Basic " +
Convert.ToBase64String(credentialBuffer);
}
else
{
throw new ApplicationException(
"No network credentials");
}
}
return request;
}[/code]This overridden function specifies that requests are to use "Basic" HTTP authentication, adding a new "Authorization" header with credentials of the form "Basic " plus the base-64-encoded "Name:Password" string. (You might need to add using System.Net; to the generated class.)
In the client code, then, you can use code similar to the following:
ProductPackagingService pps = new ProductPackagingService( );
NetworkCredential netCredential =
new NetworkCredential("Name", "Password");
Uri uri = new Uri(pps.Url);
ICredentials credentials =
netCredential.GetCredential(uri, "Basic");
pps.Credentials = credentials;
pps.PreAuthenticate = true;
// etc.
(Regarding comments about versions 5.0 and 6.1: if you're referring to FLEXnet Connect (formerly Update Service), you might consider posting to this forum.)