Parameter Serializer nullifies incoming byte array (x-post)

I

irwin.williams

Hi, i posted this message in the WSE group
(http://groups.google.com/group/microsoft.public.dotnet.framework.webservices.enhancements)
but got no response.

Hello
I am using web services to send arrays of bytes inside of messages.
The actual service i am using is hosted outside of IIS using Aaron
Skonnard's HTTPSys transport
http://pluralsight.com/blogs/aaron/archive/2005/10/14/15571.aspx, and i

am also using Custom Soap Filters to edit specific messages.

When i send a message containing properties which may themselves
contain arrays of bytes the actual message as a parameter of given
methods on the service contains the properties, except that the actual
array is empty (size = 0).


Via investigation of the methods called on the service (which extends
SoapService from WSE 3.0) , I was aided greatly by Lutz's .Net
Reflector http://www.aisto.com/roeder/dotnet/, I have found that the
call to Invoke the method on the webservice somehow causes the byte
array inside of the soap envelope to be made empty.


I have produced a small project, which i hope explains the exact issue
i am trying to deal with. Please see the code below. Any light shed
on this matter would be most appreciated.


using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml;
using System.Xml.Serialization;
using Microsoft.Web.Services3;
using System.Reflection;
using System.Web.Services.Description;


namespace ParameterSerializerTest
{
[WebService(Name = "ParameterSerializerNullBytes", Namespace =
tempnamespace)]
public class ParameterSerializerNullBytes
{
public const string tempnamespace =
"http://myNamespace.org";


public static void Main(string[] args)
{
#region Create Attachments
SpecialAttachment spa = new
SpecialAttachment();
spa.content = new byte[] { 1, 2, 3, 4, 5, 6, 7,
8, 9, 0 };
spa.name = "speelunks";
AttachmentContainer atc = new
AttachmentContainer();
atc.attachments = new
List<SpecialAttachment>();
atc.attachments.Add(spa);
atc.containername = "containerforspeelunks";
#endregion


SoapEnvelope env = new SoapEnvelope();
env.SetBodyObject(atc, tempnamespace);


#region Use reflection to get access to the
Parameter Serializer
Type receiverType =
typeof(ParameterSerializerNullBytes);
MethodInfo selectedMethodInfo =
receiverType.GetMethod("Deliver");
LogicalMethodInfo logicalMethodInfo = new
LogicalMethodInfo(selectedMethodInfo);
SoapServerMethod selectedMethod = new
SoapServerMethod(receiverType,
logicalMethodInfo);


#endregion


#region Use the serializer to get the
AttachmentContainer out of the
SoapEnvelope
XmlReader reader = env.GetBodyReader();
object[] oArray = null;
reader.ReadStartElement(reader.LocalName,
reader.NamespaceURI);
reader.MoveToContent();
oArray =
(object[])selectedMethod.ParameterSerializer.Deserialize(reader,
(selectedMethod.BindingUse == SoapBindingUse.Encoded) ?
env.CurrentSoap.EncodingStyle : null);
reader.Close();
#endregion


AttachmentContainer atcReturned = oArray[0] as
AttachmentContainer;


Console.WriteLine("content byte size BEFORE
inserting into the
SoapEnvelope: "+ Environment.NewLine +
atc.attachments[0].content.Length);


Console.WriteLine("content byte size AFTER
using the serializer:" +
Environment.NewLine + atcReturned.attachments[0].content.Length);


AttachmentContainer atcFromEnvelope =
(AttachmentContainer)env.GetBodyObject(typeof(AttachmentContainer),
tempnamespace);
Console.WriteLine("content byte size AFTER
inserting into the
SoapEnvelope:" + Environment.NewLine +
atcFromEnvelope.attachments[0].content.Length);


Console.Read();
}


[SoapDocumentMethodAttribute("Deliver",
Use = SoapBindingUse.Literal,
ParameterStyle = SoapParameterStyle.Bare)]
public void Deliver([XmlElement(Namespace =
tempnamespace,
ElementName = "AttachmentContainer")] AttachmentContainer atc)
{
}
}


[XmlType(Namespace =
ParameterSerializerNullBytes.tempnamespace,
TypeName = "SpecialAttachment")]
public class SpecialAttachment
{
[XmlElement(typeof(byte[]))]
public byte[] content;
[XmlElement()]
public string name;
}


[XmlType(Namespace =
ParameterSerializerNullBytes.tempnamespace,
TypeName = "AttachmentContainer")]
public class AttachmentContainer
{
[XmlArray()]
public List<SpecialAttachment> attachments;
[XmlElement()]
public string containername;
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top