I am generating two service reference contracts for .asmx files in Visual Studio 2010.
I created both service references in an identical fashion. I right click on 'Service References' -> 'Add Service Reference..' -> 'Discover' -> Rename Namespace -> OK.
This is the top most auto-generated code from References.cs for the properly generated service:
namespace CableSolve.Web.Api.Tests.ComponentServicesProxy {
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://www.cormant.com/cswebapi", ConfigurationName="ComponentServicesProxy.ComponentServicesSoap")]
public interface ComponentServicesSoap {
This is the code for the improperly generated service:
namespace CableSolve.Web.Api.Tests.WorkflowServicesProxy {
using System.Runtime.Serialization;
using System;
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="OrderDto", Namespace="http://www.cormant.com/cswebapi")]
[System.SerializableAttribute()]
public partial class OrderDto : object, System.Runtime.Serialization.IExtensibleDataObject, System.ComponentModel.INotifyPropertyChanged {
It is clear that WorkflowServicesProxy is using System.Runtime.Serialization where as ComponentServicesProxy is using System.ServiceModel.
I'm unsure what is triggering my second service reference to be generated using System.Runtime.Serialization. Does anyone know what would cause this? My OrderDto class does not have the DataContractAttribute, however, it does have other attributes:
[Serializable]
[XmlRoot("Order"), SoapType("Order")]
public class OrderDto : IDto
This service reference was generating code properly before. It seems that between two builds it shifted.
Declarations for both my services are identical:
[WebService(Namespace = "http://www.cormant.com/cswebapi")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class WorkflowServices : WebService
[WebService(Namespace = "http://www.cormant.com/cswebapi")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[ToolboxItem(false)]
public class ComponentServices : WebService
Service reference configurations are identical:
Update: While I tried the suggested answer without success, I have learned some information. If I remove all the code from my asmx file and re-generate the service reference, it DOES swap back to ServiceModel. So, there is something in the code itself.
You partially answered your own question
My OrderDto class does not have the DataContractAttribute
That combined with the fact that I bet that OrderDTO
resides inside the assembly CableSolve.Orders
and both the client and server share that assembly.
Because it (technically) is a known type, and it is not explicitly marked as a data contract, the code generator uses the DLL's reference and uses Runtime.Serialization
to serialize and transfer the object instead of the ServiceModel
.
As a "Solution" Change from "Reuse All" to the other option, and check all of the boxes except the one from your referenced common assembly.