.NET SOAP 常见类型 [英] .NET SOAP Common types

查看:17
本文介绍了.NET SOAP 常见类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法在创建 Web 服务时指定要使用的类型?具体来说,我希望能够在客户端和服务器上使用相同的类型以减少代码重复.

Is there a way when creating web services to specify the types to use? Specifically, I want to be able to use the same type on both the client and server to reduce duplication of code.

过度简化的例子:

    public class Name
    {
        public string FirstName {get; set;}
        public string Surname { get; set; }

        public override string ToString()
        {
            return string.Concat(FirstName, " ", Surname);
        }
    }

我不想在我的班级中重新编码部分功能.另一件事是,任何现有的操纵此类的代码都不会在客户端工作,因为生成的客户端类将是不同的类型.

I don't want to have recode pieces of functionality in my class. The other thing is that any code that exists that manipulates this class won't work client side as the client side class that is generated would be a different type.

推荐答案

好吧,我知道这是 SOAP 方面的一个明确的设计决定,因此您实际上不应该这样做.我发现以下 页面 解释了原因:

Okay, I see know that this has been an explicit design decision on the part of SOAP so you're not actually supposed to this. I found the following page that explains why:

服务共享架构和契约,不上课.服务仅在他们通过结构表达模式和行为通过合同.服务合同描述消息的结构和排序约束消息.的形式表达式允许机器验证的传入消息.机器传入消息的验证允许您保护服务的正直.契约和模式必须随着时间的推移保持稳定,因此构建他们的灵活性很重要.

Services share schema and contract, not class. Services interact solely on their expression of structures through schemas and behaviors through contracts. The service's contract describes the structure of messages and ordering constraints over messages. The formality of the expression allows machine verification of incoming messages. Machine verification of incoming messages allows you to protect the service's integrity. Contracts and schemas must remain stable over time, so building them flexibly is important.

话虽如此,还有另外两种可能:

Having said that there are two other possibilities:

  1. 在 Visual Studio 中或使用 wsdl.exe 生成 Web 引用.然后进入生成的 Reference.cs(或 .vb)文件并明确删除类型.然后重定向到位于另一个程序集中的所需类型.
  2. 您可以通过 wsdl.exe 和/sharetypes 参数在客户端的 Web 服务之间共享类型.

这篇关于.NET SOAP 常见类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆