File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33using System . Collections . Generic ;
44using System . IO ;
55using System . Linq ;
6+ using System . ServiceModel . Channels ;
67using System . Text ;
78using System . Threading . Tasks ;
9+ using System . Xml ;
810using System . Xml . Linq ;
911using Microsoft . VisualStudio . TestTools . UnitTesting ;
1012
@@ -52,5 +54,24 @@ public void TestReadBase64()
5254
5355 Assert . AreEqual ( 1336 , ms . Length ) ;
5456 }
57+
58+ [ TestMethod ]
59+ public async Task WriteTwice ( )
60+ {
61+ var body = $@ "<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"">
62+ <soapenv:Body>
63+ <Ping xmlns=""http://tempuri.org/"">
64+ <s>1</s>
65+ </Ping>
66+ </soapenv:Body>
67+ </soapenv:Envelope>
68+ " ;
69+ ParsedMessage pm = await ParsedMessage . FromStreamReaderAsync ( new StreamReader ( new MemoryStream ( Encoding . Default . GetBytes ( body ) ) ) , MessageVersion . Soap12 ) ;
70+
71+ var dw = XmlDictionaryWriter . CreateDictionaryWriter ( XmlWriter . Create ( new MemoryStream ( ) ) ) ;
72+
73+ pm . WriteBodyContents ( dw ) ;
74+ pm . WriteBodyContents ( dw ) ;
75+ }
5576 }
5677}
Original file line number Diff line number Diff line change 11using System ;
22using System . IO ;
33using System . Linq ;
4+ using System . Reflection ;
45using System . ServiceModel . Channels ;
56using System . Text ;
67using System . Threading ;
@@ -77,13 +78,22 @@ public override string ToString()
7778
7879 protected override void OnWriteBodyContents ( XmlDictionaryWriter writer )
7980 {
80- using ( var reader = GetReaderAtBodyContents ( ) )
81+ ResetMessageConsumed ( ) ;
82+
83+ using ( var reader = InternalGetReaderAtBodyContents ( ) )
8184 {
8285 writer . WriteNode ( reader , true ) ;
8386 }
8487 }
8588
8689 protected override XmlDictionaryReader OnGetReaderAtBodyContents ( )
90+ {
91+ ResetMessageConsumed ( ) ;
92+
93+ return InternalGetReaderAtBodyContents ( ) ;
94+ }
95+
96+ private XmlDictionaryReader InternalGetReaderAtBodyContents ( )
8797 {
8898 var reader = new XDocumentXmlReader ( _body ) ;
8999
@@ -175,5 +185,19 @@ private static MessageProperties ExtractSoapProperties(HttpRequest httpRequest)
175185
176186 return properties ;
177187 }
188+
189+ private void ResetMessageConsumed ( )
190+ {
191+ var stateField = typeof ( Message ) . GetProperty ( "State" ) ;
192+ if ( stateField != null )
193+ {
194+ // Set the state to 'Created' to allow reuse
195+ stateField . SetValue ( this , MessageState . Created ) ;
196+ }
197+ else
198+ {
199+ throw new InvalidOperationException ( "Unable to access the internal state field." ) ;
200+ }
201+ }
178202 }
179203}
Original file line number Diff line number Diff line change 22
33 <PropertyGroup >
44 <Description >SOAP protocol middleware for ASP.NET Core</Description >
5- <Version >1.2.1.6 </Version >
5+ <Version >1.2.1.7 </Version >
66 <Authors >Digital Design</Authors >
77 <TargetFrameworks >netstandard2.0;netstandard2.1;net8.0;netcoreapp3.1;</TargetFrameworks >
88 <PackageId >SoapCore</PackageId >
You can’t perform that action at this time.
0 commit comments