Skip to content

Commit 25a1952

Browse files
authored
Merge pull request #68 from CyberSource/bugfix-readers
Bugfix for closing reader
2 parents af287b0 + 7e0a2ee commit 25a1952

File tree

5 files changed

+34
-26
lines changed

5 files changed

+34
-26
lines changed

CyberSource.nuspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package >
33
<metadata>
44
<id>CyberSource</id>
5-
<version>1.4.5</version>
5+
<version>1.4.6</version>
66
<title>CyberSource Corporation</title>
77
<authors>CyberSource Corporation</authors>
88
<owners>CyberSource Corporation</owners>

CyberSource/Base/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
//
3232
// You can specify all the values or you can default the Revision and Build Numbers
3333
// by using the '*' as shown below:
34-
[assembly: AssemblyVersion("1.4.5")]
35-
[assembly: AssemblyFileVersion("1.4.5")]
34+
[assembly: AssemblyVersion("1.4.6")]
35+
[assembly: AssemblyFileVersion("1.4.6")]

CyberSource/Client/CustomTextMessageEncoder.cs

+28-20
Original file line numberDiff line numberDiff line change
@@ -59,35 +59,43 @@ public override Message ReadMessage(ArraySegment<byte> buffer, BufferManager buf
5959

6060
public override Message ReadMessage(Stream stream, int maxSizeOfHeaders, string contentType)
6161
{
62-
var sr = new StreamReader(stream);
63-
var wireResponse = sr.ReadToEnd();
64-
sr.Close();
62+
String wireResponse;
6563

64+
using (var sr = new StreamReader(stream))
65+
{
66+
wireResponse = sr.ReadToEnd();
67+
}
68+
6669
// Fix for Xml external entity injection violation in fortify report
6770
XmlReaderSettings settings = new XmlReaderSettings();
6871
settings.DtdProcessing = DtdProcessing.Prohibit;
6972
settings.XmlResolver = null;
7073

7174
XmlDocument doc = new XmlDocument();
72-
StringReader stringReader = new StringReader(wireResponse);
73-
XmlReader reader = XmlReader.Create(stringReader, settings);
74-
doc.Load(reader);
75-
//We need to get rid of the security header because it is not signed by the web service.
76-
//The whole reason for the custom Encoder is to do this. the client rejected the unsigned header.
77-
//Our WCF client is set up to allow the absence of a security header but if the header exists then it must be signed.
78-
//Hopefully the namespace will not change. Maybe it should be put in a config.
79-
XPathNavigator n = doc.CreateNavigator();
80-
if (n.MoveToFollowing("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"))
75+
Message returnMessage = null;
76+
77+
using (StringReader stringReader = new StringReader(wireResponse))
8178
{
82-
n.DeleteSelf();
79+
using (XmlReader reader = XmlReader.Create(stringReader, settings))
80+
{
81+
doc.Load(reader);
82+
83+
//We need to get rid of the security header because it is not signed by the web service.
84+
//The whole reason for the custom Encoder is to do this. the client rejected the unsigned header.
85+
//Our WCF client is set up to allow the absence of a security header but if the header exists then it must be signed.
86+
//Hopefully the namespace will not change. Maybe it should be put in a config.
87+
88+
XPathNavigator n = doc.CreateNavigator();
89+
if (n.MoveToFollowing("Security", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"))
90+
{
91+
n.DeleteSelf();
92+
}
93+
94+
StringReader stringReaderInnerXml = new StringReader(doc.InnerXml);
95+
XmlReader reader2 = XmlReader.Create(stringReaderInnerXml, settings);
96+
returnMessage = Message.CreateMessage(reader2, maxSizeOfHeaders, MessageVersion.Soap11);
97+
}
8398
}
84-
StringReader stringReaderInnerXml = new StringReader(doc.InnerXml);
85-
reader = XmlReader.Create(stringReaderInnerXml, settings);
86-
Message returnMessage = Message.CreateMessage(reader, maxSizeOfHeaders, MessageVersion.Soap11);
87-
88-
stringReader.Close();
89-
stringReaderInnerXml.Close();
90-
reader.Close();
9199

92100
return returnMessage;
93101
}

CyberSource/Client/Properties/AssemblyInfo.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@
3131
//
3232
// You can specify all the values or you can default the Revision and Build Numbers
3333
// by using the '*' as shown below:
34-
[assembly: AssemblyVersion("1.4.5")]
35-
[assembly: AssemblyFileVersion("1.4.5")]
34+
[assembly: AssemblyVersion("1.4.6")]
35+
[assembly: AssemblyFileVersion("1.4.6")]

CyberSourceTests/MTTest/Program.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void ThreadMethod()
7373
request.Add("billTo_ipAddress", "10.7.111.111");
7474
request.Add("card_accountNumber", "4111111111111111");
7575
request.Add("card_expirationMonth", "12");
76-
request.Add("card_expirationYear", "2020");
76+
request.Add("card_expirationYear", "2030");
7777
request.Add("purchaseTotals_currency", "USD");
7878

7979
// there are two items in this sample

0 commit comments

Comments
 (0)