Skip to content

Commit

Permalink
Merge pull request #965 from flipm0de/support-methods-with-array-of-a…
Browse files Browse the repository at this point in the history
…rray-params

Added support for array of arrays parameters in methods and a test
  • Loading branch information
andersjonsson authored Sep 29, 2023
2 parents c290514 + 4406889 commit 34d8171
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System.ServiceModel;
using System.Text;

namespace SoapCore.Tests.MessageContract.Models
{
[ServiceContract(Namespace = "http://tempuri.org")]
public interface IArrayOfArrayOfByteService
{
[OperationContract]
string ArrayOfArrayOfByteMethod(byte[][] arrayOfArrayOfByteParam);
}

public class ArrayOfArrayOfByteService : IArrayOfArrayOfByteService
{
public string ArrayOfArrayOfByteMethod(byte[][] arrayOfArrayOfByteParam)
{
var ret = new StringBuilder();
ret.Append("[");
foreach (var array in arrayOfArrayOfByteParam)
{
ret.Append("[");
ret.Append(string.Join(",", array));
ret.Append("]");
}

ret.Append("]");
return ret.ToString();
}
}
}
23 changes: 23 additions & 0 deletions src/SoapCore.Tests/MessageContract/RawRequestSoap11Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,29 @@ public async Task Soap11MessageContractArrayOfIntParamWrapped()
}
}

[TestMethod]
public async Task SoapArrayOfArrayOfByte()
{
const string body = @"<soapenv:Envelope xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/"" xmlns:tem=""http://tempuri.org"">
<soapenv:Header/>
<soapenv:Body>
<tem:ArrayOfArrayOfByteMethod>
<tem:arrayOfArrayOfByteParam><tem:base64Binary>AQI=</tem:base64Binary><tem:base64Binary>AgM=</tem:base64Binary><tem:base64Binary>BAU=</tem:base64Binary><tem:base64Binary>BgU=</tem:base64Binary></tem:arrayOfArrayOfByteParam>
</tem:ArrayOfArrayOfByteMethod>
</soapenv:Body>
</soapenv:Envelope>";

using (var host = CreateTestHost(typeof(ArrayOfArrayOfByteService)))
using (var client = host.CreateClient())
using (var content = new StringContent(body, Encoding.UTF8, "text/xml"))
using (var res = await host.CreateRequest("/Service.asmx").AddHeader("SOAPAction", @"""ArrayOfArrayOfByteMethod""").And(msg => msg.Content = content).PostAsync())
{
res.EnsureSuccessStatusCode();
var resultMessage = await res.Content.ReadAsStringAsync();
Assert.IsTrue(resultMessage.Contains("<ArrayOfArrayOfByteMethodResult>[[1,2][2,3][4,5][6,5]]</ArrayOfArrayOfByteMethodResult>"));
}
}

[TestMethod]
public async Task Soap11MessageContractComplexNotWrapped()
{
Expand Down
2 changes: 1 addition & 1 deletion src/SoapCore/SerializerHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public object DeserializeInputParameter(
switch (_serializer)
{
case SoapSerializer.XmlSerializer:
if (!parameterType.IsArray)
if (!parameterType.IsArray || parameterType.GetElementType()?.IsArray == true)
{
// case [XmlElement("parameter")] int parameter
// case [XmlArray("parameter")] int[] parameter
Expand Down

0 comments on commit 34d8171

Please sign in to comment.