Share via


ServiceAgent Constructor (String, String[], IPromptForCredentials)

Initializes a new instance of the ServiceAgent class for communicating with a specific Web service with the specified allowable authentication methods and authentication credential callback method.

Namespace:  Microsoft.CommerceServer
Assembly:  Microsoft.CommerceServer.CrossTierTypes (in Microsoft.CommerceServer.CrossTierTypes.dll)

Syntax

'Declaration
Protected Sub New ( _
    serviceUrl As String, _
    allowedAuthMethods As String(), _
    credentialPrompter As IPromptForCredentials _
)
'Usage
Dim serviceUrl As String
Dim allowedAuthMethods As String()
Dim credentialPrompter As IPromptForCredentials

Dim instance As New ServiceAgent(serviceUrl, _
    allowedAuthMethods, credentialPrompter)
protected ServiceAgent(
    string serviceUrl,
    string[] allowedAuthMethods,
    IPromptForCredentials credentialPrompter
)
protected:
ServiceAgent(
    String^ serviceUrl, 
    array<String^>^ allowedAuthMethods, 
    IPromptForCredentials^ credentialPrompter
)
protected function ServiceAgent(
    serviceUrl : String, 
    allowedAuthMethods : String[], 
    credentialPrompter : IPromptForCredentials
)

Parameters

  • serviceUrl
    Type: System..::.String
    The URL of the Web service this agent will run against.
  • allowedAuthMethods
    Type: array<System..::.String>[]()[]
    A list of authorization modes which are allowed.

Remarks

The returned ServiceAgent will not prompt on authentication failure.

Examples

This example shows how to initialize a ServiceAgent with a credentialPrompter callback.

using System.Net;
using Microsoft.CommerceServer;
using Microsoft.CommerceServer.Marketing;

public ServiceAgent CreateMarketingAgent(string url)
{
  MarketingServiceAgent mktgAgent = new MarketingServiceAgent
  (
    url, ServiceAgent.DefaultAuthMethods, new MyCredentialPrompter());
  return mktgAgent;
}

public class MyCredentialPrompter : IPromptForCredentials
{
  public NetworkCredential PromptForCredentials(string url, string authType)
  {
    // Typically these values would be retrieved from a
    // dialog box presented to a user prompting them to
    // enter authentication credentials.
    string username = "theUser";
    string password = "pwd";
    string domain = "domain";
    NetworkCredential credentials = new NetworkCredential(username, password, domain);
    return credentials;
  }
}

Permissions

See Also

Reference

ServiceAgent Class

ServiceAgent Members

ServiceAgent Overload

Microsoft.CommerceServer Namespace