-
Notifications
You must be signed in to change notification settings - Fork 0
/
MessageVersionConverter.cs
114 lines (100 loc) · 3.87 KB
/
MessageVersionConverter.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.ServiceModel;
using System.Globalization;
using System.ServiceModel.Channels;
using System.Linq;
using System.Text;
/*
* Want more WCF tips?
* Visit http://webservices20.blogspot.com/
*/
namespace WebServices20.BindingExtenions
{
/// <summary>
/// This code is a copy of System.ServiceModel.Configuration.MessageVersionConverter.
/// That class is internal so it needs to be duplicated here.
/// </summary>
class MessageVersionConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return ((typeof(string) == sourceType) || base.CanConvertFrom(context, sourceType));
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return ((typeof(InstanceDescriptor) == destinationType) || base.CanConvertTo(context, destinationType));
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
if (!(value is string))
{
return base.ConvertFrom(context, culture, value);
}
string str = (string)value;
switch (str)
{
case "Soap11WSAddressing10":
return MessageVersion.Soap11WSAddressing10;
case "Soap12WSAddressing10":
return MessageVersion.Soap12WSAddressing10;
case "Soap11WSAddressingAugust2004":
return MessageVersion.Soap11WSAddressingAugust2004;
case "Soap12WSAddressingAugust2004":
return MessageVersion.Soap12WSAddressingAugust2004;
case "Soap11":
return MessageVersion.Soap11;
case "Soap12":
return MessageVersion.Soap12;
case "None":
return MessageVersion.None;
case "Default":
return MessageVersion.Default;
}
throw new ArgumentOutOfRangeException("messageVersion", str, "The argument must be of type System.ServiceModel.Channels.MessageVersion");
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if ((typeof(string) != destinationType) || !(value is MessageVersion))
{
return base.ConvertTo(context, culture, value, destinationType);
}
MessageVersion version = (MessageVersion)value;
if (version == MessageVersion.Default)
{
return "Default";
}
if (version == MessageVersion.Soap11WSAddressing10)
{
return "Soap11WSAddressing10";
}
if (version == MessageVersion.Soap12WSAddressing10)
{
return "Soap12WSAddressing10";
}
if (version == MessageVersion.Soap11WSAddressingAugust2004)
{
return "Soap11WSAddressingAugust2004";
}
if (version == MessageVersion.Soap12WSAddressingAugust2004)
{
return "Soap12WSAddressingAugust2004";
}
if (version == MessageVersion.Soap11)
{
return "Soap11";
}
if (version == MessageVersion.Soap12)
{
return "Soap12";
}
if (version != MessageVersion.None)
{
throw new ArgumentOutOfRangeException("messageVersion", value, "The argument must be of type System.ServiceModel.Channels.MessageVersion");
}
return "None";
}
}
}