我正在为 Visual Studio 2010 中的 .asmx 文件生成两个服务参考合同。
我以相同的方式创建了两个服务引用。我右键单击“服务引用”->“添加服务引用..”->“发现”->重命名命名空间->确定。
这是来自 References.cs 的最顶级的自动生成的代码,用于正确生成的服务:
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 {
这是不正确生成的服务的代码:
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 {
很明显,WorkflowServicesProxy 使用 System.Runtime.Serialization,而 ComponentServicesProxy 使用 System.ServiceModel。
我不确定是什么触发了我使用 System.Runtime.Serialization 生成的第二个服务引用。有谁知道这会导致什么?我的 OrderDto 类没有 DataContractAttribute,但是,它确实有其他属性:
[Serializable]
[XmlRoot("Order"), SoapType("Order")]
public class OrderDto : IDto
此服务参考之前已正确生成代码。似乎在两个构建之间它发生了变化。
我的两项服务的声明是相同的:
[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
服务参考配置相同:
更新:虽然我尝试了建议的答案但没有成功,但我学到了一些信息。如果我从我的 asmx 文件中删除所有代码并重新生成服务引用,它确实会交换回 ServiceModel。所以,代码本身就有一些东西。