ASP.NET WebService ignoring return: XmlArray ElementName
This is as weird as it gets. Name given in XmlArray attrib's ElementName appears in WISDL but not in actual response. Running under 3.5 (2.0.50727 for IIS AppPool).
After more detailed digging -- autogenned WSDL has different declarations for POST/GET vs SOAP responses and the diff is that they just reference the autogenned elem/type for array and not the whole response type/elem which has new name.
The question still remians - WHY is this happening and more importantly how to fix it?
Here are the Details:
WebMethod:
[WebMethod]
[return: XmlArray(ElementName = "TickTick")]
public TTickerItem[] GetActiveTickerItems2(uint version, uint language, uint locale, int startIndex, int maxItems)
In WSDL:
<s:element name="GetActiveTickerItems2Response">
<s:complexType>
<s:sequence>
<s:element minOccurs="0" maxOccurs="1" name="TickTick" type="tns:ArrayOfTTickerItem" />
</s:sequence>
</s:complexType>
</s:element>
<wsdl:message name="GetActiveTickerItems2SoapIn">
<wsdl:part name="parameters" element="tns:GetActiveTickerItems2" />
</wsdl:message>
<wsdl:message name="GetActiveTickerItems2SoapOut">
<wsdl:part name="parameters" element="tns:GetActiveTickerItems2Response" />
</wsdl:message>
Auto-genned test page shows examples with new name (TickTick).
Actual Response:
<ArrayOfTTickerItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<TTickerItem>
<m_message>New 开发者_运维百科Ticker 1st Message</m_message>
<m_priority>2</m_priority>
<m_messageType>0</m_messageType>
<m_data1>0</m_data1>
<m_data2>13</m_data2>
</TTickerItem>
. . . . . . . .
</ArrayOfTTickerItem>
Slightly different declarations for GET/POST - misses the new name:
<wsdl:message name="GetActiveTickerItems2HttpGetOut">
<wsdl:part name="Body" element="tns:ArrayOfTTickerItem" />
</wsdl:message>
. . . . . . .
<wsdl:message name="GetActiveTickerItems2HttpPostOut">
<wsdl:part name="Body" element="tns:ArrayOfTTickerItem" />
</wsdl:message>
It can still be the matter of some settings, part of web.config (I have just plain add name="HttpGet" and HttpPost under //system.web/webServices/protocols xpath which has always been enough) ...
I'm afraid I'll have to close this one as a bug in ASP.NET since I have consistent repro and no one said that it worked with their setups. Will keep it on for a few more days, just in case.
Have you tried updating the web reference in your asp.net project?
I know this question was asked a while ago now but it still comes up google and I have been struggling with the same problem a little today so i thought this may help someone else...
The reason for it is because the element in question is is the root node in the output...to make it work as expected the webmethod should be defined as:
[WebMethod]
[return: XmlArray(ElementName = "TickTick"),XmlRoot(ElementName = "TickTick")]
public TTickerItem[] GetActiveTickerItems2(uint version, uint language, uint locale, int startIndex, int maxItems)
精彩评论