Help with XmlSchemaException

Topics: General Discussion Forum
Mar 27, 2007 at 3:57 PM
Edited Mar 27, 2007 at 4:00 PM
For some reason, even though this operation is only declared once in my project, I get this exception:

An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is:
System.InvalidOperationException: An exception was thrown in a call to a WSDL export extension: System.ServiceModel.Description.DataContractSerializerOperationBehavior
contract: http://foo.com/MyProject/2007/04:MyService ----> System.Xml.Schema.XmlSchemaException: The global element http://foo.com/MyProject/2007/04:SomeMethodResponse' has already been declared.
at System.Xml.Schema.XmlSchemaSet.InternalValidationCallback(Object sender, ValidationEventArgs e)
...

Removing the namespace/name declaration from the DataContract for the SomeMethodResponse class fixes it...any thoughts?

System.Runtime.Serialization.DataContractAttribute(Namespace = "http://foo.com/MyProject/2007/04", Name = "SomeMethodResponse")

public class SomeMethodResponse

{

}


Thanks,
Mark
Developer
Mar 28, 2007 at 1:12 AM
Can you elaborate a bit further on the scenario where this exception is being thrown?
1) Which recipe you are running
2) The solution folder structure
3) Environment: OS, VS version, SPs, GAX version

Thanks,
Charly
Mar 28, 2007 at 8:56 PM
This is being thrown when browsing the service endpoint (.svc) in the browser. I'm using the Service Factory (WCF) guidance package. I have one project for the service, as opposed to separate projects for DataContracts, ServiceImplementation, etc. Running XP x64 SP2, VS 2005 SP1, GAX Feb 2007.

Another experiment did work for me: altering the datacontracts' namespaces to match my C# namespace. So instead of http://foo.com/MyProject/2007/04 I now have http://foo.com/MyProject.DataContracts/2007/04. I kept the former namespace for the ServiceContract and ServiceBehavior.

I'm still baffled by why it would create dupes in a single namespace even if each class is uniquely declared.

Thanks,
Mark
Developer
Mar 29, 2007 at 1:51 AM
Since you put everything in one project, then you may have "collisions" with the namespaces. That is not realted to the CLR types (Class names) but to the way the WSDL is generated so each object (element) will get its reference to a namespace and there you may have troubles when using the same for all references.
Try to follow the same approach as the package and use a different namespace for your ServiceContracts and your DataContracts elements, and you should be fine.