File

projects/wms-framework/src/lib/wcfserviceinvocationsupport/ChannelBase.ts

Description

Base class for communication channels

Index

Properties
Methods
Accessors

Constructor

constructor(client: ClientBase<T>)

Constructor

Parameters :
Name Type Optional Description
client ClientBase<T> No

the client base to set to the HttpChannel

Properties

Public httpClient
Type : HttpClient
Default value : null

Optional angular HttpClient instance to use with this object

Public innerChannel
Type : WcfChannelBase

Suffix added to the URL when performing request. This suffix is defined in the specific endpoint for JSON services

Methods

BeginInvoke
BeginInvoke(methodName: string, requestArgs: any[], callback: AsyncCallback, asyncState: any)

Initiates the request for the given service method

Parameters :
Name Type Optional Description
methodName string No

name of the service method to call

requestArgs any[] No

either a collection like [{name: any, value: any}] or [any] to use for method arguments

callback AsyncCallback No

request callback

asyncState any No

asycn state

Returns : IAsyncResult

{IAsyncResult} the result

EndInvoke
EndInvoke(methodName: string, requestArgs: any[], result: IAsyncResult, classConstructor?: any)

Ends the request for the given service method

Parameters :
Name Type Optional Description
methodName string No

name of the service method to call

requestArgs any[] No

either a collection like [{name: any, value: any}] or [any] to use for method arguments

result IAsyncResult No
classConstructor any Yes
Returns : any

{IAsyncResult} the result

Accessors

HttpClient
getHttpClient()

Gets the httpClient property value

setHttpClient(value: any)

Sets the httpClient property value

Parameters :
Name Type Optional
value any No
Returns : void
EndpointSuffix
getEndpointSuffix()

Gets the EndpointSuffix property value

Returns : string
setEndpointSuffix(value: string)

Sets the EndpointSuffix property value

Parameters :
Name Type Optional
value string No
Returns : void
UsePost
getUsePost()

Gets the usePost property value

Returns : boolean
setUsePost(value: boolean)

Sets the usePost property value

Parameters :
Name Type Optional
value boolean No
Returns : void
InnerChannel
getInnerChannel()

Gets the innerChannel property value

setInnerChannel(value: any)

Sets the innerChannel property value

Parameters :
Name Type Optional
value any No
Returns : void
import { IAsyncResult, AsyncCallback } from './AsyncResultSupport';
import { ClientBase } from './ClientBase';
import { Uri } from '../baseframework';
import { HttpClient } from '@angular/common/http';
import { WcfBindingContext } from './WcfBindingContext';
import { WcfChannelBase } from './CommunicationSupport';
import { WcfChannelFactoryBase } from './WcfChannelFactoryBase';
import { EndpointAddress } from './EndpointAddress';
import { HttpChannel } from './HttpChannel';
import { Message } from './Message';

/**
 *  Base class for communication channels
 *
 * @export
 * @class ChannelBase
 * @template T
 * @wType System.ServiceModel.ClientBase`1+ChannelBase`1
 */
export class ChannelBase<T> {
  /**
   *  Optional angular HttpClient instance to use with this object
   *
   * @type {HttpClient}
   * @memberof ChannelBase
   */
  public httpClient: HttpClient = null;

  /**
   * Gets the httpClient property value
   *
   * @memberof ChannelBase
   * @wIgnore
   */
  get HttpClient() {
    return this.httpClient;
  }

  /**
   * Sets the httpClient property value
   *
   * @memberof ChannelBase
   * @wIgnore
   */
  set HttpClient(value: any) {
    this.httpClient = value;
    this.innerChannel.HttpClient = this.httpClient;
  }

  /**
   * Gets the EndpointSuffix property value
   *
   * @memberof ChannelBase
   * @wIgnore
   */
  get EndpointSuffix(): string {
    return this.client.binding.EndpointSuffix;
  }
  /**
   * Sets the EndpointSuffix property value
   *
   * @memberof ChannelBase
   * @wIgnore
   */
  set EndpointSuffix(value: string) {
    /* istanbul ignore else */
    if (this.client.binding) {
      this.client.binding.EndpointSuffix = value;
    }
  }

  /**
   * Gets the usePost property value
   *
   * @memberof ChannelBase
   * @wIgnore
   */
  get UsePost(): boolean {
    return this.client.binding.UsePost;
  }

  /**
   * Sets the usePost property value
   *
   * @memberof ChannelBase
   * @wIgnore
   */
  set UsePost(value: boolean) {
    /* istanbul ignore else */
    if (this.client.binding) {
      this.client.binding.UsePost = value;
    }
  }

  /**
   * Suffix added to the URL when performing request. This suffix is defined in the specific endpoint for JSON services
   *
   * @memberof ChannelBase
   */
  public innerChannel: WcfChannelBase;

  /**
   * Gets the innerChannel property value
   *
   * @memberof ChannelBase
   * @wIgnore
   */
  get InnerChannel() {
    return this.innerChannel;
  }

  /**
   * Sets the innerChannel property value
   *
   * @memberof ChannelBase
   * @wIgnore
   */
  set InnerChannel(value: any) {
    this.innerChannel = value;
  }

  /**
   *  Constructor
   *
   * @param {ClientBase} client the client base to set to the HttpChannel
   * @memberof ChannelBase
   */
  constructor(private client: ClientBase<T>) {
    const context = new WcfBindingContext();
    let channelFactory: WcfChannelFactoryBase<T> = null;
    /* istanbul ignore else */
    if (this.client.binding) {
      const bindings = this.client.binding.CreateBindingElements();
      for (const binding of bindings) {
        channelFactory = binding.BuildChannelFactory(null, context);
        /* istanbul ignore else */
        if (channelFactory) {
          this.innerChannel = channelFactory.OnCreateChannel(
            new EndpointAddress(new Uri(this.client.url)),
            new Uri(this.client.url)
          );
        }
      }
    }
    // defaulting inner channel to HttpChannel
    /* istanbul ignore else */
    if (!this.innerChannel) {
      this.innerChannel = new HttpChannel<T>(this.client);
    }
  }

  /**
   *  Ends the request for the given service method
   *
   * @param {string} methodName name of the service method to call
   * @param {any[]} requestArgs either a collection like [{name: any, value: any}] or [any] to use for method arguments
   * @param {AsyncCallback} callback request callback
   * @param {*} asyncState asycn state
   * @return {*}  {IAsyncResult} the result
   * @memberof ChannelBase
   */
  EndInvoke(
    methodName: string,
    requestArgs: any[],
    result: IAsyncResult,
    classConstructor?: any
  ): any {
    result.classConstructor = classConstructor;
    let res = this.innerChannel.EndRequest(result);
    return res.result;
  }

  /**
   *  Initiates the request for the given service method
   *
   * @param {string} methodName name of the service method to call
   * @param {any[]} requestArgs either a collection like [{name: any, value: any}] or [any] to use for method arguments
   * @param {AsyncCallback} callback request callback
   * @param {*} asyncState asycn state
   * @return {*}  {IAsyncResult} the result
   * @memberof ChannelBase
   */
  BeginInvoke(
    methodName: string,
    requestArgs: any[],
    callback: AsyncCallback,
    asyncState: any
  ): IAsyncResult {
    let message: Message = this.client.binding.CreateMessage(
      this.client.url,
      methodName,
      requestArgs
    );
    return this.innerChannel.BeginRequestWithTimeout(
      message,
      null,
      callback,
      asyncState
    );
  }
}

result-matching ""

    No results matching ""