projects/wms-framework/src/lib/wcfserviceinvocationsupport/channels.ts
Interface that must be implemented by channel factories that create type-specific channels.
Methods |
CreateChannel | |||||||||
CreateChannel(to: EndpointAddress, via: Uri)
|
|||||||||
Parameters :
Returns :
any
|
GetProperty | ||||||
GetProperty(TParam: ClassType)
|
||||||
Type parameters :
|
||||||
Gets the property
Parameters :
Returns :
T
{T} |
OnCreateChannel | |||||||||
OnCreateChannel(to: EndpointAddress, via: Uri)
|
|||||||||
OnCreateChannel method
Parameters :
Returns :
any
{*} |
import { Uri } from '../baseframework/Uri';
import {
ICommunicationObject,
CommunicationBinding,
} from './CommunicationSupport';
import { SimpleList } from '../baseframework/collections';
import { EndpointAddress } from './EndpointAddress';
import { WcfBindingElement } from './WcfBindingElement';
import { WcfBindingContext } from './WcfBindingContext';
import { WcfChannelFactoryBase } from './WcfChannelFactoryBase';
import { WcfMessage } from './WcfMessage';
import {
ClassType,
tryExplicitDeserialization,
tryImplicitDeserialization,
} from '../baseframework';
import { Message } from './Message';
/**
* Interface that must be implemented by channel factories that create type-specific channels.
*
* @export
* @interface IChannelFactory
* @extends {ICommunicationObject}
* @template T The type of channel that the channel factory creates.
* @wInterface System.ServiceModel.Channels.IChannelFactory`1
*/
export interface IChannelFactory<T> extends ICommunicationObject {
CreateChannel(to: EndpointAddress, via: Uri): any;
/**
* OnCreateChannel method
*
* @param {EndpointAddress} to
* @param {Uri} via
* @return {*} {*}
* @memberof IChannelFactory
* @wIgnore
*/
OnCreateChannel(to: EndpointAddress, via: Uri): any;
/**
* Gets the property
*
* @template T
* @param {ClassType} TParam
* @return {*} {T}
* @memberof IChannelFactory
* @wIgnore
*/
GetProperty<T>(TParam: ClassType): T;
}
/**
* Represents the binding element used to specify an HTTP transport for transmitting messages.
*
* @export
* @class HttpTransportBindingElement
* @extends {WcfBindingElement}
* @wType System.ServiceModel.Channels.HttpTransportBindingElement
*/
export class HttpTransportBindingElement extends WcfBindingElement {
/**
* Creates a channel factory that can be used to create a channel.
*
* @template TChannel
* @param {Function} TChannelParam
* @param {WcfBindingContext} context
* @return {*} {WcfChannelFactoryBase<TChannel>}
* @memberof HttpTransportBindingElement
* @wNoMap
*/
public BuildChannelFactory<TChannel>(
TChannelParam: Function,
context: WcfBindingContext
): WcfChannelFactoryBase<TChannel> {
return null;
}
public MaxBufferSize: number = 0;
/**
* MaxReceivedMessageSize property
*
* @type {number}
* @memberof HttpTransportBindingElement
* @wIgnore
*/
public MaxReceivedMessageSize: number = 0;
}
/**
* Represents the binding element used to specify an HTTPS transport for transmitting messages.
*
* @export
* @class HttpsTransportBindingElement
* @extends {HttpTransportBindingElement}
* @wType System.ServiceModel.Channels.HttpsTransportBindingElement
*/
export class HttpsTransportBindingElement extends HttpTransportBindingElement {}
/**
* The binding element that specifies the .NET Binary Format for XML used to encode messages.
*
* @export
* @class BinaryMessageEncodingBindingElement
* @extends {WcfBindingElement}
* @wType System.ServiceModel.Channels.BinaryMessageEncodingBindingElement
*/
export class BinaryMessageEncodingBindingElement extends WcfBindingElement {
/**
* Builds the channel factory stack on the client that creates a specified type of channel for a specified context.
*
* @template TChannel
* @param {Function} TChannelParam
* @param {WcfBindingContext} context
* @return {*} {WcfChannelFactoryBase<TChannel>}
* @memberof BinaryMessageEncodingBindingElement
* @wNoMap
*/
public BuildChannelFactory<TChannel>(
TChannelParam: Function,
context: WcfBindingContext
): WcfChannelFactoryBase<TChannel> {
return null;
}
}
/**
* The collection of binding elements used in a binding.
*
* @export
* @class BindingElementCollection
* @extends {SimpleList<WcfBindingElement>}
* @wType System.ServiceModel.Channels.BindingElementCollection
*/
export class BindingElementCollection extends SimpleList<WcfBindingElement> {}
/**
* Defines a binding from a list of binding elements.
*
* @export
* @class WcfCustomBinding
* @extends {CommunicationBinding}
* @wType System.ServiceModel.Channels.CustomBinding
*/
export class WcfCustomBinding extends CommunicationBinding {
Elements: BindingElementCollection = new BindingElementCollection();
constructor() {
super();
this.UsePost = true;
}
CreateBindingElements(): any {
return this.Elements;
}
/**
* CreateMessage method
*
* @param {string} baseUrl
* @param {string} methodName
* @param {any[]} args
* @return {*} {Message}
* @memberof WcfCustomBinding
* @wIgnore
*/
CreateMessage(baseUrl: string, methodName: string, args: any[]): Message {
let message = new WcfMessage();
/* istanbul ignore next */
if (this.EndpointSuffix) {
message.EndpointSuffix = this.EndpointSuffix;
}
message.BaseUrl = baseUrl;
message.UsePost = this.UsePost;
message.methodName = methodName;
message.requestArgs = args;
message.Headers.clear(); //Cleaning previous headers sent before
return message;
}
/**
* CreateResponseMessage method
*
* @param {*} result
* @param {*} [classConstructor]
* @return {*} {Message}
* @memberof WcfCustomBinding
* @wIgnore
*/
CreateResponseMessage(result: any, classConstructor?: any): Message {
let resultToTransfer = null;
if (
result?.AsyncState?.d ||
result?.AsyncState?.d === '' ||
result?.AsyncState?.d === 0
) {
resultToTransfer = tryImplicitDeserialization(
result.AsyncState.d,
classConstructor
);
if (typeof classConstructor !== 'undefined') {
let convertedToType = resultToTransfer instanceof classConstructor;
if (!convertedToType) {
if (resultToTransfer instanceof Array) {
return new classConstructor(resultToTransfer);
} else {
return tryExplicitDeserialization(
resultToTransfer,
classConstructor
);
}
}
}
}
let resultMessage = new WcfMessage();
resultMessage.result = resultToTransfer;
return resultMessage;
}
}