Reputation: 55
We have a WCF service that we recently moved all of the operations over to be asynchronous. We rolled this out with a new service contract to cover those operations, but both the new contract's ServiceContract
Name and the OperationContract
Names are pointed to the old ServiceContract
and OperationContract
Names to maintain backwards compatibility.
Something like this:
[ServiceContract(Namespace= "", Name = nameof(IOldContract))]
public interface INewAsyncContract
{
[WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest)]
[OperationContract(Name = nameof(IOldContract.DoThing))]
Task<DoThingResponse> DoThingAsync(DoThingRequest doThingRequest);
}
Whereas the old contract looks like this:
[ServiceContract]
public interface IOldContract
{
[WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest)]
[OperationContract]
DoThingResponse DoThing(DoThingRequest doThingRequest);
}
Note: The old service contract is missing a namespace value. This is accurate in the codebase.
Now for the issue:
When we deploy this service with a ServiceContract
Namespace in the new service contract, we receive this error when navigating to the service:
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: IOldContract ----> System.Xml.Schema.XmlSchemaException: The global element 'DoThingResponse' has already been declared.
And conversely, if we publish without the namespace, the service operates as expected, but a default namespace is provided (http://tempuri.org), which we don't want.
Why is the ServiceContract
namespace interfering with the declation of DoThingResponse?
Edit to add DoThingResponse definition:
[DataContract(Namespace = "")]
public class DoThingResponse
{
[DataMember]
public obj ResponseObj { get; set; }
}
Upvotes: 0
Views: 146
Reputation: 7522
It seems that we have declared the DoThingResponse repeatedly. I would like to know the way you define the custom class and the project structure.
The namespace attribute and name attribute of the service contract are applied to the metadata document exposed by the service (WSDL document). The namespace attribute is used as the namespace of the porttype element in the WSDL document. The default value is http://tempuri.org.
The name attribute applies the name of the porttype element in the WSDL document.
These values are unique and cannot be repeated.
Unique values are used to mark the elements in the envelope in the SOAP envelope.
Feel free to let me know if there is anything I can help with.
Upvotes: 1