projects/wms-framework/src/lib/wcfserviceinvocationsupport/ChannelBase.ts
Base class for communication channels
Properties |
|
Methods |
Accessors |
constructor(client: ClientBase<T>)
|
||||||||
Constructor
Parameters :
|
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 |
BeginInvoke | ||||||||||||||||||||
BeginInvoke(methodName: string, requestArgs: any[], callback: AsyncCallback, asyncState: any)
|
||||||||||||||||||||
Initiates the request for the given service method
Parameters :
Returns :
IAsyncResult
{IAsyncResult} the result |
EndInvoke | ||||||||||||||||||||
EndInvoke(methodName: string, requestArgs: any[], result: IAsyncResult, classConstructor?: any)
|
||||||||||||||||||||
Ends the request for the given service method
Parameters :
Returns :
any
{IAsyncResult} the result |
HttpClient | ||||||
getHttpClient()
|
||||||
Gets the httpClient property value |
||||||
setHttpClient(value: any)
|
||||||
Sets the httpClient property value
Parameters :
Returns :
void
|
EndpointSuffix | ||||||
getEndpointSuffix()
|
||||||
Gets the EndpointSuffix property value
Returns :
string
|
||||||
setEndpointSuffix(value: string)
|
||||||
Sets the EndpointSuffix property value
Parameters :
Returns :
void
|
UsePost | ||||||
getUsePost()
|
||||||
Gets the usePost property value
Returns :
boolean
|
||||||
setUsePost(value: boolean)
|
||||||
Sets the usePost property value
Parameters :
Returns :
void
|
InnerChannel | ||||||
getInnerChannel()
|
||||||
Gets the innerChannel property value |
||||||
setInnerChannel(value: any)
|
||||||
Sets the innerChannel property value
Parameters :
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
);
}
}