c# - Visual Studio 使用 Runtime.Serialization 生成我的服务引用之一,但其他使用 ServiceModel 生成

标签 c# .net web-services soap service-reference

我正在 Visual Studio 2010 中为 .asmx 文件生成两个服务引用契约(Contract)。

我以相同的方式创建了两个服务引用。我右键单击“服务引用”->“添加服务引用..”->“发现”->重命名命名空间->确定。

这是为正确生成的服务从 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

服务引用配置相同:

enter image description here

更新:虽然我尝试了建议的答案但没有成功,但我学到了一些信息。如果我从我的 asmx 文件中删除所有代码并重新生成服务引用,它确实会换回 ServiceModel。所以,代码本身有一些东西。

最佳答案

你部分回答了你自己的问题

My OrderDto class does not have the DataContractAttribute

再加上我敢打赌 OrderDTO 驻留在程序集 CableSolve.Orders 中并且客户端和服务器共享该程序集这一事实。

因为它(技术上)是已知类型,并且没有明确标记为数据协定,所以代码生成器使用 DLL 的引用并使用 Runtime.Serialization 来序列化和传输对象的 ServiceModel

enter image description here

作为“解决方案”,从“全部重用”更改为另一个选项,并选中除引用的通用程序集中的复选框之外的所有复选框。

关于c# - Visual Studio 使用 Runtime.Serialization 生成我的服务引用之一,但其他使用 ServiceModel 生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12480659/

相关文章:

c# - 指定的包无效。主要部分缺失

c# - Windows 四月更新后我的应用程序停止提供静态文件

c# - 如何使用 Magick.Net 调整 jpeg 质量

c# - Moq - 检查方法是否被模拟(设置)

c# - 帮助抽象类/类/接口(interface)单元的结构

javascript - 如何访问代码隐藏中存储过程返回的值

objective-c - 连接到服务器

android - 将 Android Web 服务连接到本地主机

c# - 使用 selenium C# 在文本字段上执行键盘敲击 "Ctrl + A" "Ctrl + C"和 "Ctrl + V"#

iphone - 按住按钮直到 Action 在 ios 中执行