1 //
2 // WsdlContractConversionContext.cs
3 //
4 // Author:
5 //	Atsushi Enomoto <atsushi@ximian.com>
6 //	Ankit Jain <jankit@novell.com>
7 //
8 // Copyright (C) 2005 Novell, Inc.  http://www.novell.com
9 //
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:
17 //
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
20 //
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.
28 //
29 using System;
30 using System.Collections.ObjectModel;
31 using System.Linq;
32 using System.ServiceModel;
33 using System.ServiceModel.Channels;
34 using System.ServiceModel.Configuration;
35 using System.Web.Services.Description;
36 using System.Xml;
37 
38 namespace System.ServiceModel.Description
39 {
40 	[MonoTODO]
41 	public class WsdlContractConversionContext
42 	{
43 		ContractDescription contract;
44 		PortType port_type;
45 
WsdlContractConversionContext(ContractDescription contract, PortType portType)46 		internal WsdlContractConversionContext (ContractDescription contract, PortType portType)
47 		{
48 			this.contract = contract;
49 			this.port_type = portType;
50 		}
51 
52 		public ContractDescription Contract {
53 			get { return contract; }
54 		}
55 
56 		public PortType WsdlPortType {
57 			get { return port_type; }
58 		}
59 
GetMessageDescription( OperationMessage operationMessage)60 		public MessageDescription GetMessageDescription (
61 			OperationMessage operationMessage)
62 		{
63 			if (operationMessage == null)
64 				throw new ArgumentNullException ("operationMessage");
65 			var od = GetOperationDescription (operationMessage.Operation);
66 			if (od == null)
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);
69 		}
70 
GetOperation(OperationDescription operation)71 		public Operation GetOperation (OperationDescription operation)
72 		{
73 			if (operation == null)
74 				throw new ArgumentNullException ("operation");
75 			foreach (Operation o in WsdlPortType.Operations)
76 				if (o.Name == operation.Name)
77 					return o;
78 			return null;
79 		}
80 
GetOperationDescription( Operation operation)81 		public OperationDescription GetOperationDescription (
82 			Operation operation)
83 		{
84 			if (operation == null)
85 				throw new ArgumentNullException ("operation");
86 			return Contract.Operations.FirstOrDefault (od => od.Name == operation.Name);
87 		}
88 
GetOperationMessage( MessageDescription message)89 		public OperationMessage GetOperationMessage (
90 			MessageDescription message)
91 		{
92 			if (message == null)
93 				throw new ArgumentNullException ("message");
94 			var od = Contract.Operations.FirstOrDefault (o => o.Messages.Contains (message));
95 			if (od == null)
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)
101 					return om;
102 			return null;
103 		}
104 	}
105 }
106