Geospatial and location based services became very popular these days. One concern for developers of such applications is how to represent the data in the system. This includes simple data types such as points or coordinate systems and complex ones such as advanced topologies. The correct approach is of course to use types from the standard schema set of the Open Geospatial Consortium (OGC).
For a .Net developer this may imply the following needs:
Use xsd.exe to generate classes for serizliation
Create .Net 2.0 / WCF web services that utilize these schemas
Consume Wsdl's with these schemas
Unfortunetely the OpenGIS standard schemas are not interoperable with .Net. This has already been noticed by developers for older OpenGIS versions but newer versions seem to be equality incompatible.
If you only want the fix without the details download it here and see in the end of the post the fix details:
Here are some of the errors one gets when trying to consume Gml 3.1.1 and Gml 3.2.1 schemas in .Net:
Gml 3.1.1 - WCF
While using "add service reference" we get this error:
And after this an empty proxy code is generated:
Gml 3.1.1 - .Net 2.0
The wsdl importing stage seems to work fine. Let's build a one line client:
Such a simple client - what can possibly go wrong? Well nothing, except this:
And this is after I have omitted some inner exceptions.
In some cases (depending on .Net 2.0 patch level) the below exception will appear - not much improvement:
Finally, depending in the types we reference, we might get this one as well:
Gml 3.2.1 - WCF
Proxy is generated but the simplest client throws this exception chain:
Gml 3.2.1 - .Net 2.0
Guess what?
Why these errors happen?
The errors appear in run-time when we instantiate the client proxy or web service. At this stage .Net creates the serialization assembly for each type and fails to do it for the proxy. Actually if we have marked the "generate serialization assembly" build option we could already see these errors in compile time.
Now what?
We need to fix the schemas or the proxy in order to make them interoperable with .Net. The fix must be compatible with the original schema, so it may change the schema syntax but must result in an isomorphic schema.
Making Gml 3.2.1 work
There are two reasons for this schema incomparability:
Cyclic schema references
From gml.xsd:
From deprecatedTypes.xsd:
One way to solve this is to remove deprecatedTypes.xsd altogether - it is not really required. We'll be nicer and just replace inside it the reference to gml.xsd with these direct references:
Non-string lists
.Net does not support the xsd:list data type. When the list is of strings it works anyway since unresolved types are treated as strings. But for other types it is not supported. MSDN contains some more information on xsd:list support in .Net.
basicTypes.xsd contains this:
Which becomes this in the .Net proxy:
which causes a run-time error since the XmlTextAttribute is only appropriate on strings.
The solutions is to replace all non-string lists in the schema to strings so the above becomes:
And after this Gml 3.2.1 classes are serializable by .Net!
Making Gml 3.1.1 work
This version has two issues:
Same issue with lists as in 3.2.1 - same fix
I've seen this one a couple of times. Basically when there is a multidimensional array of a type which has a single child element in some cases .Net code generation is incorrect. Don't ask, long story... Just replace in geometryPrimitives.xsd:
With:
And we have 3.1.1 working as well!
Download fix
I have uploaded the fixed schemas to save your time:
After you extract the zip the fixed schemas are in the below folders: