2 // WsdlContractConversionContext.cs
5 // Atsushi Enomoto <atsushi@ximian.com>
6 // Ankit Jain <jankit@novell.com>
8 // Copyright (C) 2005 Novell, Inc. http://www.novell.com
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Collections.ObjectModel;
32 using System.ServiceModel;
33 using System.ServiceModel.Channels;
34 using System.ServiceModel.Configuration;
35 using System.Web.Services.Description;
38 namespace System.ServiceModel.Description
41 public class WsdlContractConversionContext
43 ContractDescription contract;
46 internal WsdlContractConversionContext (ContractDescription contract, PortType portType)
48 this.contract = contract;
49 this.port_type = portType;
52 public ContractDescription Contract {
53 get { return contract; }
56 public PortType WsdlPortType {
57 get { return port_type; }
60 public MessageDescription GetMessageDescription (
61 OperationMessage operationMessage)
63 if (operationMessage == null)
64 throw new ArgumentNullException ("operationMessage");
65 var od = GetOperationDescription (operationMessage.Operation);
67 throw new ArgumentException (String.Format ("Operation {0} for the argument OperationMessage was not found", operationMessage.Operation.Name));
68 return od.Messages.FirstOrDefault (md => md.Direction == MessageDirection.Input && operationMessage is OperationInput || md.Direction == MessageDirection.Output && operationMessage is OperationOutput);
71 public Operation GetOperation (OperationDescription operation)
73 if (operation == null)
74 throw new ArgumentNullException ("operation");
75 foreach (Operation o in WsdlPortType.Operations)
76 if (o.Name == operation.Name)
81 public OperationDescription GetOperationDescription (
84 if (operation == null)
85 throw new ArgumentNullException ("operation");
86 return Contract.Operations.FirstOrDefault (od => od.Name == operation.Name);
89 public OperationMessage GetOperationMessage (
90 MessageDescription message)
93 throw new ArgumentNullException ("message");
94 var od = Contract.Operations.FirstOrDefault (o => o.Messages.Contains (message));
96 throw new ArgumentException (String.Format ("MessageDescription for {0} direction and {1} action was not in current ContractDescription", message.Direction, message.Action));
97 var op = GetOperation (od);
98 foreach (OperationMessage om in op.Messages)
99 if (om is OperationInput && message.Direction == MessageDirection.Input ||
100 om is OperationOutput && message.Direction == MessageDirection.Output)