MetaMessage.cs
3.01 KB
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
using System;
using System.Linq;
using System.ServiceModel.Channels;
using System.Xml;
using SoapCore.ServiceModel;
namespace SoapCore.Meta
{
internal class MetaMessage : Message
{
private readonly Message _message;
private readonly ServiceDescription _service;
private readonly Binding _binding;
public MetaMessage(Message message, ServiceDescription service, Binding binding)
{
_message = message;
_service = service;
_binding = binding;
}
public override MessageHeaders Headers
{
get { return _message.Headers; }
}
public override MessageProperties Properties
{
get { return _message.Properties; }
}
public override MessageVersion Version
{
get { return _message.Version; }
}
protected override void OnWriteStartEnvelope(XmlDictionaryWriter writer)
{
writer.WriteStartElement("wsdl", "definitions", "http://schemas.xmlsoap.org/wsdl/");
writer.WriteAttributeString("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
writer.WriteAttributeString("xmlns:msc", "http://schemas.microsoft.com/ws/2005/12/wsdl/contract");
writer.WriteAttributeString("xmlns:wsp", "http://schemas.xmlsoap.org/ws/2004/09/policy");
writer.WriteAttributeString("xmlns:wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
writer.WriteAttributeString("xmlns:http", "http://schemas.microsoft.com/ws/06/2004/policy/http");
// Soap11
if (Version == MessageVersion.Soap11 || Version == MessageVersion.Soap11WSAddressingAugust2004 || Version == MessageVersion.Soap11WSAddressingAugust2004)
{
writer.WriteAttributeString("xmlns:soap", "http://schemas.xmlsoap.org/wsdl/soap/");
}
// Soap12
else if (Version == MessageVersion.Soap12WSAddressing10 || Version == MessageVersion.Soap12WSAddressingAugust2004)
{
writer.WriteAttributeString("xmlns:soap", "http://schemas.xmlsoap.org/wsdl/soap12/");
}
else
{
throw new ArgumentOutOfRangeException(nameof(Version), "Unsupported MessageVersion encountered while writing envelope.");
}
writer.WriteAttributeString("xmlns:tns", _service.Contracts.First().Namespace);
writer.WriteAttributeString("xmlns:wsam", "http://www.w3.org/2007/05/addressing/metadata");
writer.WriteAttributeString("targetNamespace", _service.Contracts.First().Namespace);
writer.WriteAttributeString("name", _service.ServiceType.Name);
if (_binding != null && _binding.HasBasicAuth())
{
writer.WriteStartElement("wsp:Policy");
writer.WriteAttributeString("wsu:Id", $"{_binding.Name}_{_service.Contracts.First().Name}_policy");
writer.WriteStartElement("wsp:ExactlyOne");
writer.WriteStartElement("wsp:All");
writer.WriteStartElement("http:BasicAuthentication");
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
writer.WriteEndElement();
}
}
protected override void OnWriteStartBody(XmlDictionaryWriter writer)
{
}
protected override void OnWriteBodyContents(XmlDictionaryWriter writer)
{
_message.WriteBodyContents(writer);
}
}
}