cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Ilion_Blaze
Level 2

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:


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?
Labels (1)
0 Kudos
(3) Replies
lemairel
Level 2

Hello,

I am encountering the exact same problem. Did you find a solution ?

Regards,

L. LEMAIRE
0 Kudos
imhttran
Level 2

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 .
0 Kudos
RobertDickau
Flexera Alumni

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:
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.)
0 Kudos