Note that there are some explanatory texts on larger screens.

plurals
  1. POApply KnownTypeAttribute to Object type?
    primarykey
    data
    text
    <p>I'm attempting to use the WeatherBug API (WSDL is <a href="http://api.wxbug.net/weatherservice.asmx?WSDL" rel="nofollow">here</a>). I'm attempting to learn some things about WCF.</p> <p>I used svcutil.exe to create the classes from the WSDL from the link above.</p> <p>I then tried to execute the following code to test it:</p> <pre><code>var proxy = new WeatherBugWebServicesSoapClient(); var stations = proxy.GetStationListByUSZipCode("97211", UnitType.English, "myapikey"); </code></pre> <p>I end up getting a <code>NetDispatcherFaultException</code>:</p> <blockquote> <p>The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter <a href="http://api.wxbug.net/:GetStationListByUSZipCodeResponse" rel="nofollow">http://api.wxbug.net/:GetStationListByUSZipCodeResponse</a>. The InnerException message was 'Error in line 1 position 352. Element '<a href="http://api.wxbug.net/:anyType" rel="nofollow">http://api.wxbug.net/:anyType</a>' contains data from a type that maps to the name '<a href="http://api.wxbug.net/:ApiStationData" rel="nofollow">http://api.wxbug.net/:ApiStationData</a>'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'ApiStationData' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details.</p> </blockquote> <p>It appears that I should be getting back an object of type <code>ArrayOfAnyType</code> that is declared like this (generated by svcutil.exe):</p> <pre><code>[System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")] [System.Runtime.Serialization.CollectionDataContractAttribute(Name = "ArrayOfAnyType", Namespace = "http://api.wxbug.net/", ItemName = "anyType")] public class ArrayOfAnyType : System.Collections.Generic.List&lt;object&gt; { } </code></pre> <p>The array looks like it should be a collection of <code>ApiStationData</code>, which is declared like this:</p> <pre><code>[System.Diagnostics.DebuggerStepThroughAttribute()] [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")] [System.Runtime.Serialization.DataContractAttribute(Name = "ApiStationData", Namespace = "http://api.wxbug.net/")] public partial class ApiStationData : object, System.Runtime.Serialization.IExtensibleDataObject { </code></pre> <p>From what I've read on various web pages, I <em>think</em> I need to add a <code>KnownTypeAttribute</code> to the <code>Object</code> class, since the <code>ArrayOfAnyType</code> is a <code>List&lt;object&gt;</code>. I don't think that's possible, though (or correct)...</p> <p>It's also odd that the exception mentions <code>http://api.wxbug.net/:anyType</code>, but there isn't a definition for <code>anyType</code> in the svcutil generated code (which is why I'm making the assumption about the <code>ArrayOfAnyType</code>).</p> <p>Any suggestions on how to solve this issue?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload