简体   繁体   English

添加 WCF 服务作为 web 参考和服务参考时的不同代理 class

[英]Different proxy class when adding WCF service as web reference and service reference

There is a web service written with WCF that I'm adding as reference.有一个用 WCF 编写的 web 服务作为参考添加。 Proxy class generator works flawlessly when I add it to as service reference but it generates a slightly different class when I add it as web reference using service.svc?WSDL . Proxy class generator works flawlessly when I add it to as service reference but it generates a slightly different class when I add it as web reference using service.svc?WSDL . Here's are the differences:以下是不同之处:

//service reference
public partial class TestServicesClient : ... // correct class name
{
    public int TestMethod(string serviceID, int dealID) // correct method signature
    { ... }
}

//web reference
public partial class TestServices: ... //different class name
{
    public void TestMethod(string serviceID, int dealID, bool dealIDSpecified, out int TestMethodResult, out bool TestMethodResultSpecified) // different method signature
    { ... }
}

I tried using wsdl.exe for generating web reference class, didn't help.我尝试使用 wsdl.exe 生成 web 参考 class,没有帮助。

What is wrong here?这里有什么问题?

Nothing is wrong here.这里没有错。 Service Reference is the "new" way to use a WCF Service, it removes overhead such as the "Specified"-parameter, "Result"-parameter and "Result Specificed"-parameter. Service Reference是使用 WCF 服务的“新”方式,它消除了诸如“指定”参数、“结果”参数和“结果指定”参数等开销。

You can still use other properties/methods to check if a parameter is specified or if there is a result.您仍然可以使用其他属性/方法来检查是否指定了参数或是否有结果。 But before WCF, it changed the method signature.但在 WCF 之前,它改变了方法签名。

You use a Service Reference and a Web Reference a bit different and that's just the way it is.您使用服务参考和 Web 参考有点不同,这就是它的方式。

Here's some additional reading:这里有一些额外的阅读:

And to quote from a reply to "What is the difference between WCF service and web service"并引用对“WCF 服务和 web 服务有什么区别”的回复

WCF "web services" are part of a much broader spectrum of remote communication enabled through WCF. WCF “Web 服务”是通过 WCF 实现的更广泛远程通信的一部分。 You will get a much higher degree of flexibility and portability doing things in WCF than through traditional ASMX because WCF is designed, from the ground up, to summarize all of the different distributed programming infrastructures offered by MS.您将在 WCF 中获得比传统 ASMX 更高程度的灵活性和可移植性,因为 WCF 从头开始设计,总结了 MS 提供的所有不同分布式编程基础设施。 An endpoint in WCF can be communicated with just as easily over SOAP/XML as it can over TCP/binary and to change this medium is simply a configuration file mod. WCF 中的端点可以通过 SOAP/XML 与通过 TCP/二进制文件一样容易地进行通信,并且更改此介质只是一个配置文件 mod。 In theory this reduces the amount of new code needed when porting or changing business needs, targets, etc.从理论上讲,这减少了移植或更改业务需求、目标等时所需的新代码量。

ASMX is older than WCF, and anything ASMX can do so can WCF (and more). ASMX 早于 WCF,ASMX 可以做到的任何事情都可以 WCF(以及更多)。 Basically you can see WCF as trying to logically group together all the different ways of getting two apps to communicate in the world of MS;基本上,您可以看到 WCF 试图在逻辑上将让两个应用程序在 MS 世界中进行通信的所有不同方式组合在一起; ASMX was just one of these many ways and so is now grouped under the WCF umbrella of capabilities. ASMX 只是众多方式中的一种,因此现在归入 WCF 功能保护伞下。

There are few difference between the service reference and web reference.服务参考和 web 参考之间几乎没有区别。 WCF serializes using datacontract serializer. WCF 使用数据合同序列化程序进行序列化。 So add XmlSerializeFormat attribute to the serivcecontract and then add web reference.因此,将 XmlSerializeFormat 属性添加到服务合同,然后添加 web 引用。 Your extra parameters will be removed.您的额外参数将被删除。 But then its like using wcf like web service only.但是,它就像使用 wcf 一样仅像 web 服务。 One more retriction is that you need to use web bindings only like http.另一个限制是您只需要使用 web 绑定,例如 http。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM