service-model
Version:
An object oriented web service framework inspired by Windows Communication Foundation.
50 lines (49 loc) • 2.44 kB
JavaScript
var rpcFaultFormatter_1 = require("../dispatcher/rpcFaultFormatter");
var rpcMessageFormatter_1 = require("../dispatcher/rpcMessageFormatter");
var rpcOperationSelector_1 = require("../dispatcher/rpcOperationSelector");
var addressMessageFilter_1 = require("../dispatcher/addressMessageFilter");
/**
* Endpoint behavior that enables RPC communication on an endpoint.
*
* <uml>
* hide members
* hide circle
* EndpointBehavior <|.. RpcBehavior
* </uml>
*/
var RpcBehavior = (function () {
function RpcBehavior() {
}
RpcBehavior.prototype.applyEndpointBehavior = function (description, endpoint) {
endpoint.faultFormatter = this.createFaultFormatter();
endpoint.operationSelector = this.createOperationSelector(description, endpoint);
endpoint.filter = this.createMessageFilter(endpoint);
// Note that we assume the operations in the dispatcher line up with the operations in the description. This is
// true if the dispatcher is created through the DispatcherFactory but could be incorrect otherwise. We'll at
// least check that the names are the same.
var operations = description.contract.operations;
if (operations.length != endpoint.operations.length) {
throw new Error("DispatchEndpoint and EndpointDescripition do not have the same number of operations.");
}
for (var i = 0; i < operations.length; i++) {
if (endpoint.operations[i].name != operations[i].name) {
throw new Error("Mismatch between operations in DispatchEndpoint and EndpointDescription");
}
endpoint.operations[i].formatter = this.createMessageFormatter(endpoint, operations[i]);
}
};
RpcBehavior.prototype.createFaultFormatter = function () {
return new rpcFaultFormatter_1.RpcFaultFormatter();
};
RpcBehavior.prototype.createMessageFilter = function (endpoint) {
return new addressMessageFilter_1.AddressMessageFilter(endpoint.address).and(endpoint.filter);
};
RpcBehavior.prototype.createOperationSelector = function (description, endpoint) {
return new rpcOperationSelector_1.RpcOperationSelector(endpoint);
};
RpcBehavior.prototype.createMessageFormatter = function (endpoint, operation) {
return new rpcMessageFormatter_1.RpcMessageFormatter(operation);
};
return RpcBehavior;
})();
exports.RpcBehavior = RpcBehavior;