本文整理汇总了C#中System.ServiceModel.Description.ContractDescription类的典型用法代码示例。如果您正苦于以下问题:C# ContractDescription类的具体用法?C# ContractDescription怎么用?C# ContractDescription使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ContractDescription类属于System.ServiceModel.Description命名空间,在下文中一共展示了ContractDescription类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddBindingParameters
/**
* The execution of this behavior comes rather late.
* Anyone that inspects the service description in the meantime,
* such as for metadata generation, won't see the protection level that we want to use.
*
* One way of doing it is at when create HostFactory
*
* ServiceEndpoint endpoint = host.Description.Endpoints.Find(typeof(IService));
* OperationDescription operation = endpoint.Contract.Operations.Find("Action");
* MessageDescription message = operation.Messages.Find("http://tempuri.org/IService/ActionResponse");
* MessageHeaderDescription header = message.Headers[new XmlQualifiedName("aheader", "http://tempuri.org/")];
* header.ProtectionLevel = ProtectionLevel.Sign;
*
* **/
public void AddBindingParameters(ContractDescription contractDescription, ServiceEndpoint endpoint, BindingParameterCollection bindingParameters)
{
ChannelProtectionRequirements requirements = bindingParameters.Find<ChannelProtectionRequirements>();
XmlQualifiedName qName = new XmlQualifiedName(header, ns);
MessagePartSpecification part = new MessagePartSpecification(qName);
requirements.OutgoingSignatureParts.AddParts(part, action);
}
示例2: ConfigureRouterViaCode
private static void ConfigureRouterViaCode(ServiceHost serviceHost)
{
//This code sets up the Routing Sample via code. Rename or delete the App.config file
//and comment out this method call to run a config-based Routing Service
//set up some communication defaults
string deadAddress = "net.tcp://localhost:9090/servicemodelsamples/fakeDestination";
string realAddress = "net.tcp://localhost:8080/servicemodelsamples/service";
string routerAddress = "http://localhost/routingservice/router";
//note that the calculator client will be communicating to the Routing Service via basic
//HTTP, while the Routing Service is using Net.TCP to communicate to the calculator service.
//This demonstrates the Routing Service's capability of bridging between different message
//transports, formats, bindings, etc. This automatic message conversion is governed by
//whether or not SoapProcessing (enabled by default) is enabled on the Routing Configuration.
Binding routerBinding = new BasicHttpBinding();
Binding clientBinding = new NetTcpBinding();
//add the endpoint the router will use to recieve messages
serviceHost.AddServiceEndpoint(typeof(IRequestReplyRouter), routerBinding, routerAddress);
//create the client endpoint the router will route messages to
//note that the contract description on the client endpoints is actually unused, so
//this could be any string. The contract specified here goes unused
//because the Routing Service replaces this contract with one of the Router
//contracts at runtime, depending on the contract that a message was received with.
ContractDescription contract = new ContractDescription("IRequestReplyRouter");
ServiceEndpoint fakeDestination = new ServiceEndpoint(contract, clientBinding, new EndpointAddress(deadAddress));
ServiceEndpoint realDestination = new ServiceEndpoint(contract, clientBinding, new EndpointAddress(realAddress));
//create the endpoint list that contains the service endpoints we want to route to
List<ServiceEndpoint> backupList = new List<ServiceEndpoint>();
//add the endpoints in the order that the Routing Service should contact them
//first add the endpoint that we know will be down
//clearly, normally you wouldn't know that this endpoint was down by default
backupList.Add(fakeDestination);
//then add the endpoint that will work
//the Routing Service will attempt to send to this endpoint only if it
//encounters a TimeOutException or CommunicationException when sending
//to the previous endpoint in the list.
backupList.Add(realDestination);
//create the default RoutingConfiguration option
RoutingConfiguration rc = new RoutingConfiguration();
//add a MatchAll filter to the Routing Configuration's filter table
//map it to the list of endpoints defined above
//when a message matches this filter, it will be sent to the endpoints in the list in order
//if an endpoint is down or doesn't respond (which the first client won't
//since no service exists at that endpoint), the Routing Service will automatically move the message
//to the next endpoint in the list and try again.
rc.FilterTable.Add(new MatchAllMessageFilter(), backupList);
//create the Routing Behavior with the Routing Configuration and add it to the
//serviceHost's Description.
serviceHost.Description.Behaviors.Add(new RoutingBehavior(rc));
}
示例3: ApplyClientBehavior
/// <summary>
///
/// </summary>
/// <param name="contractDescription"></param>
/// <param name="endpoint"></param>
/// <param name="clientRuntime"></param>
public void ApplyClientBehavior(
ContractDescription contractDescription,
ServiceEndpoint endpoint,
ClientRuntime clientRuntime)
{
// empty
}
示例4: ApplyDispatchBehavior
public void ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime)
{
var behavior =
dispatchRuntime.ChannelDispatcher.Host.Description.FindBehavior
<WebAuthenticationConfigurationBehavior,
WebAuthenticationConfigurationAttribute>(b => b.BaseBehavior);
if (behavior == null)
behavior = contractDescription.FindBehavior
<WebAuthenticationConfigurationBehavior,
WebAuthenticationConfigurationAttribute>(b => b.BaseBehavior);
if (behavior == null)
throw new ServiceAuthenticationConfigurationMissingException();
var authorizationBehavior =
dispatchRuntime.ChannelDispatcher.Host.Description.FindBehavior
<WebAuthorizationConfigurationBehavior,
WebAuthorizationConfigurationAttribute>(b => b.BaseBehavior);
Type authorizationPolicy = null;
if (authorizationBehavior != null)
authorizationPolicy = authorizationBehavior.AuthorizationPolicyType;
foreach (var endpointDispatcher in dispatchRuntime.ChannelDispatcher.Endpoints)
endpointDispatcher.DispatchRuntime.MessageInspectors.Add(
new ServiceAuthenticationInspector(
behavior.ThrowIfNull().AuthenticationHandler,
behavior.UsernamePasswordValidatorType,
behavior.RequireSecureTransport,
behavior.Source,
authorizationPolicy));
}
示例5: MethodInfoOperationSelector
void IContractBehavior.ApplyDispatchBehavior(ContractDescription description, ServiceEndpoint endpoint, DispatchRuntime dispatch)
{
if (dispatch.ClientRuntime != null)
{
dispatch.ClientRuntime.OperationSelector = new MethodInfoOperationSelector(description, MessageDirection.Output);
}
}
示例6: ApplyDispatchBehavior
public void ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, DispatchRuntime dispatchRuntime)
{
if (dispatchRuntime == null)
throw new ArgumentNullException("dispatchRuntime");
dispatchRuntime.InstanceProvider = this.instanceProvider;
dispatchRuntime.InstanceContextInitializers.Add((IInstanceContextInitializer) new UnityInstanceContextInitializer());
}
示例7: ApplyDispatchBehavior
public void ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.DispatchRuntime dispatchRuntime)
{
// We iterate over the operation descriptions in the contract and
// try to locate an DispatchBodyElementAttribute behaviors on each
// operation. If found, we add the operation, keyed by QName of the body element
// that selects which calls shall be dispatched to this operation to a
// dictionary.
Dictionary<XmlQualifiedName,string> dispatchDictionary = new Dictionary<XmlQualifiedName,string>();
foreach( OperationDescription operationDescription in contractDescription.Operations )
{
DispatchBodyElementAttribute dispatchBodyElement =
operationDescription.Behaviors.Find<DispatchBodyElementAttribute>();
if ( dispatchBodyElement != null )
{
dispatchDictionary.Add(dispatchBodyElement.QName, operationDescription.Name);
}
}
// Lastly, we create and assign and instance of our operation selector that
// gets the dispatch dictionary we've just created.
dispatchRuntime.OperationSelector =
new DispatchByBodyElementOperationSelector(
dispatchDictionary,
dispatchRuntime.UnhandledDispatchOperation.Name);
}
示例8: MethodInfoOperationSelector
internal MethodInfoOperationSelector(ContractDescription description, MessageDirection directionThatRequiresClientOpSelection)
{
operationMap = new Dictionary<object, string>();
for (int i = 0; i < description.Operations.Count; i++)
{
OperationDescription operation = description.Operations[i];
if (operation.Messages[0].Direction == directionThatRequiresClientOpSelection)
{
if (operation.SyncMethod != null)
{
if (!operationMap.ContainsKey(operation.SyncMethod.MethodHandle))
operationMap.Add(operation.SyncMethod.MethodHandle, operation.Name);
}
if (operation.BeginMethod != null)
{
if (!operationMap.ContainsKey(operation.BeginMethod.MethodHandle))
{
operationMap.Add(operation.BeginMethod.MethodHandle, operation.Name);
operationMap.Add(operation.EndMethod.MethodHandle, operation.Name);
}
}
if (operation.TaskMethod != null)
{
if (!operationMap.ContainsKey(operation.TaskMethod.MethodHandle))
{
operationMap.Add(operation.TaskMethod.MethodHandle, operation.Name);
}
}
}
}
}
示例9: NotImplementedException
void IContractBehavior.ApplyDispatchBehavior (
ContractDescription description,
ServiceEndpoint endpoint,
DispatchRuntime dispatch)
{
throw new NotImplementedException ();
}
示例10: ServiceContractGenerationContext
public ServiceContractGenerationContext (
ServiceContractGenerator serviceContractGenerator,
ContractDescription contract,
CodeTypeDeclaration contractType)
: this (serviceContractGenerator, contract, contractType, null)
{
}
示例11: ApplyDispatchBehavior
public void ApplyDispatchBehavior(
ContractDescription contractDescription,
ServiceEndpoint endpoint,
DispatchRuntime dispatchRuntime)
{
dispatchRuntime.InstanceProvider = this;
}
示例12: ComPlusThreadInitializer
public ComPlusThreadInitializer(ContractDescription contract, DispatchOperation operation, ServiceInfo info)
{
this.info = info;
this.iid = contract.ContractType.GUID;
if (info.CheckRoles)
{
string[] serviceRoleMembers = null;
string[] contractRoleMembers = null;
string[] operationRoleMembers = null;
serviceRoleMembers = info.ComponentRoleMembers;
foreach (ContractInfo info2 in this.info.Contracts)
{
if (!(info2.IID == this.iid))
{
continue;
}
contractRoleMembers = info2.InterfaceRoleMembers;
foreach (System.ServiceModel.ComIntegration.OperationInfo info3 in info2.Operations)
{
if (info3.Name == operation.Name)
{
operationRoleMembers = info3.MethodRoleMembers;
break;
}
}
if (operationRoleMembers == null)
{
throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(Error.ListenerInitFailed(System.ServiceModel.SR.GetString("ComOperationNotFound", new object[] { contract.Name, operation.Name })));
}
break;
}
this.comAuth = new ComPlusAuthorization(serviceRoleMembers, contractRoleMembers, operationRoleMembers);
}
}
示例13: ApplyDispatchBehavior
/// <summary>
/// 注册 服务实例创建提供者,将基于PIAB的实例生成器注入WCF扩展
/// </summary>
/// <param name="contractDescription"></param>
/// <param name="endpoint"></param>
/// <param name="dispatchRuntime"></param>
public void ApplyDispatchBehavior(ContractDescription contractDescription, ServiceEndpoint endpoint,
DispatchRuntime dispatchRuntime)
{
Type serviceContractType = contractDescription.ContractType;
dispatchRuntime.InstanceProvider = new PolicyInjectionInstanceProvider(serviceContractType,
this.PolicyInjectorName);
}
示例14: ApplyDispatchBehavior
public void ApplyDispatchBehavior(ContractDescription description, ServiceEndpoint endpoint, System.ServiceModel.Dispatcher.DispatchRuntime dispatch)
{
foreach (OperationDescription opDesc in description.Operations)
{
ApplyDataContractSurrogate(opDesc);
}
}
示例15: AddPingToContractDescription
/// <summary>
/// Add the Ping method to the existing contract
/// </summary>
private void AddPingToContractDescription(ContractDescription contractDescription)
{
OperationDescription pingOperationDescription = new OperationDescription(PingOperationName, contractDescription);
MessageDescription inputMessageDescription = new MessageDescription(
GetAction(contractDescription, PingOperationName),
MessageDirection.Input);
MessageDescription outputMessageDescription = new MessageDescription(
GetAction(contractDescription, PingResponse),
MessageDirection.Output);
MessagePartDescription returnValue = new MessagePartDescription("PingResult", contractDescription.Namespace);
returnValue.Type = typeof(DateTime);
outputMessageDescription.Body.ReturnValue = returnValue;
inputMessageDescription.Body.WrapperName = PingOperationName;
inputMessageDescription.Body.WrapperNamespace = contractDescription.Namespace;
outputMessageDescription.Body.WrapperName = PingResponse;
outputMessageDescription.Body.WrapperNamespace = contractDescription.Namespace;
pingOperationDescription.Messages.Add(inputMessageDescription);
pingOperationDescription.Messages.Add(outputMessageDescription);
pingOperationDescription.Behaviors.Add(new DataContractSerializerOperationBehavior(pingOperationDescription));
pingOperationDescription.Behaviors.Add(new PingOperationBehavior());
contractDescription.Operations.Add(pingOperationDescription);
}