<p>Help!  I have an Axis web service that is being consumed by a C# application.  Everything works great, except that arrays of long values always come across as [0,0,0,0] - the right length, but the values aren't deserialized.  I have tried with other primitives (ints, doubles) and the same thing happens.  What do I do?  I don't want to change the semantics of my service.</p>

[{'answer_id': 30172, 'author': 'Chris Marasti-Georg', 'author_id': 96, 'author_profile': 'https://Stackoverflow.com/users/96', 'pm_score': 4, 'selected': True, 'text': '<p>Here\'s what I ended up with.  I have never found another solution out there for this, so if you have something better, by all means, contribute.</p>\n\n<p>First, the long array definition in the wsdl:types area:</p>\n\n<pre><code>  &lt;xsd:complexType name="ArrayOf_xsd_long"&gt;\n    &lt;xsd:complexContent mixed="false"&gt;\n      &lt;xsd:restriction base="soapenc:Array"&gt;\n        &lt;xsd:attribute wsdl:arrayType="soapenc:long[]" ref="soapenc:arrayType" /&gt;\n      &lt;/xsd:restriction&gt;\n    &lt;/xsd:complexContent&gt;\n  &lt;/xsd:complexType&gt;\n</code></pre>\n\n<p>Next, we create a SoapExtensionAttribute that will perform the fix.  It seems that the problem was that .NET wasn\'t following the multiref id to the element containing the double value.  So, we process the array item, go find the value, and then insert it the value into the element:</p>\n\n<pre><code>[AttributeUsage(AttributeTargets.Method)]\npublic class LongArrayHelperAttribute : SoapExtensionAttribute\n{\n    private int priority = 0;\n\n    public override Type ExtensionType\n    {\n        get { return typeof (LongArrayHelper); }\n    }\n\n    public override int Priority\n    {\n        get { return priority; }\n        set { priority = value; }\n    }\n}\n\npublic class LongArrayHelper : SoapExtension\n{\n    private static ILog log = LogManager.GetLogger(typeof (LongArrayHelper));\n\n    public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute)\n    {\n        return null;\n    }\n\n    public override object GetInitializer(Type serviceType)\n    {\n        return null;\n    }\n\n    public override void Initialize(object initializer)\n    {\n    }\n\n    private Stream originalStream;\n\n    private Stream newStream;\n\n    public override void ProcessMessage(SoapMessage m)\n    {\n        switch (m.Stage)\n        {\n            case SoapMessageStage.AfterSerialize:\n                newStream.Position = 0; //need to reset stream \n                CopyStream(newStream, originalStream);\n                break;\n\n            case SoapMessageStage.BeforeDeserialize:\n                XmlWriterSettings settings = new XmlWriterSettings();\n                settings.Indent = false;\n                settings.NewLineOnAttributes = false;\n                settings.NewLineHandling = NewLineHandling.None;\n                settings.NewLineChars = "";\n                XmlWriter writer = XmlWriter.Create(newStream, settings);\n\n                XmlDocument xmlDocument = new XmlDocument();\n                xmlDocument.Load(originalStream);\n\n                List&lt;XmlElement&gt; longArrayItems = new List&lt;XmlElement&gt;();\n                Dictionary&lt;string, XmlElement&gt; multiRefs = new Dictionary&lt;string, XmlElement&gt;();\n                FindImportantNodes(xmlDocument.DocumentElement, longArrayItems, multiRefs);\n                FixLongArrays(longArrayItems, multiRefs);\n\n                xmlDocument.Save(writer);\n                newStream.Position = 0;\n                break;\n        }\n    }\n\n    private static void FindImportantNodes(XmlElement element, List&lt;XmlElement&gt; longArrayItems,\n                                           Dictionary&lt;string, XmlElement&gt; multiRefs)\n    {\n        string val = element.GetAttribute("soapenc:arrayType");\n        if (val != null &amp;&amp; val.Contains(":long["))\n        {\n            longArrayItems.Add(element);\n        }\n        if (element.Name == "multiRef")\n        {\n            multiRefs[element.GetAttribute("id")] = element;\n        }\n        foreach (XmlNode node in element.ChildNodes)\n        {\n            XmlElement child = node as XmlElement;\n            if (child != null)\n            {\n                FindImportantNodes(child, longArrayItems, multiRefs);\n            }\n        }\n    }\n\n    private static void FixLongArrays(List&lt;XmlElement&gt; longArrayItems, Dictionary&lt;string, XmlElement&gt; multiRefs)\n    {\n        foreach (XmlElement element in longArrayItems)\n        {\n            foreach (XmlNode node in element.ChildNodes)\n            {\n                XmlElement child = node as XmlElement;\n                if (child != null)\n                {\n                    string href = child.GetAttribute("href");\n                    if (href == null || href.Length == 0)\n                    {\n                        continue;\n                    }\n                    if (href.StartsWith("#"))\n                    {\n                        href = href.Remove(0, 1);\n                    }\n                    XmlElement multiRef = multiRefs[href];\n                    if (multiRef == null)\n                    {\n                        continue;\n                    }\n                    child.RemoveAttribute("href");\n                    child.InnerXml = multiRef.InnerXml;\n                    if (log.IsDebugEnabled)\n                    {\n                        log.Debug("Replaced multiRef id \'" + href + "\' with value: " + multiRef.InnerXml);\n                    }\n                }\n            }\n        }\n    }\n\n    public override Stream ChainStream(Stream s)\n    {\n        originalStream = s;\n        newStream = new MemoryStream();\n        return newStream;\n    }\n\n    private static void CopyStream(Stream from, Stream to)\n    {\n        TextReader reader = new StreamReader(from);\n        TextWriter writer = new StreamWriter(to);\n        writer.WriteLine(reader.ReadToEnd());\n        writer.Flush();\n    }\n}\n</code></pre>\n\n<p>Finally, we tag all methods in the Reference.cs file that will be deserializing a long array with our attribute:</p>\n\n<pre><code>    [SoapRpcMethod("", RequestNamespace="http://some.service.provider",\n        ResponseNamespace="http://some.service.provider")]\n    [return : SoapElement("getFooReturn")]\n    [LongArrayHelper]\n    public Foo getFoo()\n    {\n        object[] results = Invoke("getFoo", new object[0]);\n        return ((Foo) (results[0]));\n    }\n</code></pre>\n\n<p>This fix is long-specific, but it could probably be generalized to handle any primitive type having this problem.</p>\n'}, {'answer_id': 570459, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 1, 'selected': False, 'text': '<p>Found this link that may offer a better alternative:  <a href="http://www.tomergabel.com/GettingWCFAndApacheAxisToBeFriendly.aspx" rel="nofollow noreferrer">http://www.tomergabel.com/GettingWCFAndApacheAxisToBeFriendly.aspx</a></p>\n'}, {'answer_id': 650260, 'author': 'Tomer Gabel', 'author_id': 11558, 'author_profile': 'https://Stackoverflow.com/users/11558', 'pm_score': 2, 'selected': False, 'text': '<p>Here\'s a more or less copy-pasted version of a <a href="http://www.tomergabel.com/GettingWCFAndApacheAxisToBeFriendly.aspx" rel="nofollow noreferrer">blog post</a> I wrote on the subject.</p>\n\n<p>Executive summary: You can either change the way .NET deserializes the result set (see Chris\'s solution above), or you can reconfigure Axis to serialize its results in a way that\'s compatible with the .NET SOAP implementation.</p>\n\n<p>If you go the latter route, here\'s how:</p>\n\n<blockquote>\n  <p>... the generated\n  classes look and appear to function\n  normally, but if you\'ll look at the\n  deserialized array on the client\n  (.NET/WCF) side you\'ll find that the\n  array has been deserialized\n  incorrectly, and all values in the\n  array are 0. You\'ll have to manually\n  look at the SOAP response returned by\n  Axis to figure out what\'s wrong;\n  here\'s a sample response (again,\n  edited for clarity):</p>\n</blockquote>\n\n<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;\n&lt;soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/&gt;\n    &lt;soapenv:Body&gt;\n        &lt;doSomethingResponse&gt;\n          &lt;doSomethingReturn&gt;\n            &lt;doSomethingReturn href="#id0"/&gt;\n            &lt;doSomethingReturn href="#id1"/&gt;\n            &lt;doSomethingReturn href="#id2"/&gt;\n            &lt;doSomethingReturn href="#id3"/&gt;\n            &lt;doSomethingReturn href="#id4"/&gt;\n          &lt;/doSomethingReturn&gt;\n        &lt;/doSomethingResponse&gt;\n        &lt;multiRef id="id4"&gt;5&lt;/multiRef&gt;\n        &lt;multiRef id="id3"&gt;4&lt;/multiRef&gt;\n        &lt;multiRef id="id2"&gt;3&lt;/multiRef&gt;\n        &lt;multiRef id="id1"&gt;2&lt;/multiRef&gt;\n        &lt;multiRef id="id0"&gt;1&lt;/multiRef&gt;\n   &lt;/soapenv:Body&gt;\n&lt;/soapenv:Envelope&gt;\n</code></pre>\n\n<blockquote>\n  <p>You\'ll notice that Axis does not\n  generate values directly in the\n  returned element, but instead\n  references external elements for\n  values. This might make sense when\n  there are many references to\n  relatively few discrete values, but\n  whatever the case this is not properly\n  handled by the WCF basicHttpBinding\n  provider (and reportedly by gSOAP and\n  classic .NET web references as well).</p>\n  \n  <p>It took me a while to find a solution:\n  edit your Axis deployment\'s\n  server-config.wsdd file and find the\n  following parameter:</p>\n</blockquote>\n\n<pre><code>&lt;parameter name="sendMultiRefs" value="true"/&gt;\n</code></pre>\n\n<blockquote>\n  <p>Change it to false,\n  then redeploy via the command line,\n  which looks (under Windows) something\n  like this:</p>\n</blockquote>\n\n<pre><code>java -cp %AXISCLASSPATH% org.apache.axis.client.AdminClient server-config.wsdl \n</code></pre>\n\n<blockquote>\n  <p>The web service\'s\n  response should now be deserializable\n  by your .NET client.</p>\n</blockquote>\n'}]
['https://Stackoverflow.com/questions/30171', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/96/']