简体   繁体   English

为什么WCF的工作方式与ASMX不同?

[英]Why doesn't WCF work the same way as ASMX?

Not sure what I'm doing wrong but I have two services one is WCF and the other is a ASMX service. 不知道我做错了什么,但我有两个服务,一个是WCF,另一个是ASMX服务。

I'm trying to call array of doubles the same way I did in my asmx version. 我试图像在我的asmx版本中那样调用双打数组。

Here is an image of the two services: 这是两个服务的图像:

在此输入图像描述

I got a fix to being able to call that method but I would like to know why ArrayOfDouble isn't showing up the same way in my serviceref2 as my serviceref1? 我得到了一个能够调用该方法的修复,但我想知道为什么ArrayOfDouble在我的serviceref2中没有像我的serviceref1那样出现?

This is the WCF version: 这是WCF版本:

namespace WcfSum
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface SumListWCF
    {

        [OperationContract]
        string CalculateSum(List<double> listDouble);
    }
}

namespace WcfSum
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    public class SumList : SumListWCF
    {
        public string CalculateSum(List<double> listDouble)
        {
            return listDouble.Sum().ToString();
        }
    }
}

This is the ASMX version: 这是ASMX版本:

namespace CalculateWebServiceSum
{
    /// <summary>
    /// Summary description for Service1
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class SumList : System.Web.Services.WebService
    {
        [WebMethod]
        public string CalculateSum(List<double> listDouble)
        {
            return listDouble.Sum().ToString();

             //return listDouble.Select(n => (double)n).ToString();
        }
    }
}

Previous post was here: WCF array of doubles not called successfully 上一篇文章在这里: 未成功调用WCF双打数组

This provided the fix but doesn't explain why it doesn't operate the same way. 这提供了修复,但没有解释为什么它不以相同的方式运行。 Or if there was a way of getting it to act the same. 或者,如果有办法让它采取相同的行动。 Which makes me feel like im fundamentally missing something? 这让我觉得我从根本上缺少一些东西?

EDIT 编辑

Ps these are just running locally. 这些只是在本地运行。

There is nothing in the SOAP or WSDL standards that specifies how something like a List<double> should be serialized. SOAP或WSDL标准中没有任何内容指定如何序列化List<double> ASMX apparently invented a complexType in the XML schema to represent array of double. ASMX显然在XML模式中发明了一个complexType来表示double的数组。

WCF is much better than ASMX. WCF比ASMX好得多。 When you use "Add Service Reference", you get to decide how to handle repeated elements like your array of doubles. 当您使用“添加服务引用”时,您可以决定如何处理重复元素,例如您的双精度数组。 You can choose for them to be treated as an array, as a List<T> , etc. 您可以选择将它们视为数组,作为List<T>等。

There would be negative value in restricting WCF to the limitations of ASMX, which is a legacy technology. 将WCF限制为ASMX的限制将是负面的价值,ASMX是一项传统技术。

You are using a generic List<> parameter, which is not supported for asmx and wcf due to interoperability with languages that do not support generic collections. 您正在使用通用List <>参数,由于与不支持通用集合的语言的互操作性,asmx和wcf不支持该参数。 See also these questions . 另见这些 问题

This question mentions a generated ArrayOfInt, so the ArrayOf* type name may be a, uhm, generic solution to deal with generic types. 这个问题提到了生成的ArrayOfInt,因此ArrayOf *类型名称可能是处理泛型类型的通用解决方案。

暂无
暂无

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

相关问题 为什么我们不能像使用 WCF 或 ASMX 那样在 Visual Studio 中添加 Web API 作为“服务引用”? - Why can't we add a Web API as a “service reference” in Visual Studio the same way we can with WCF or ASMX? 为什么我的WCF wshttpbinding客户端不能在另一台计算机上工作? - Why is my WCF wshttpbinding client doesn't work at another computer? 为什么远程调试不适用于IIS托管的WCF服务? - Why doesn't remote debugging work for WCF service hosted by IIS? WCF-重试不起作用? - WCF - retry doesn't work? 为什么动画“高度”属性不适用于Windows Universal App,其方式与“不透明度”属性相同? - Why animation “Height” property doesn't work for Windows Universal App in the same way as “Opacity” property? SQL查询在Asmx Web服务中不起作用 - SQL Query doesn't work in asmx web service Web服务asmx Xamarin.Form不起作用 - Web Service asmx Xamarin.Form doesn't work 为什么在同一个(UI)线程中顺序调用AsyncLock与不同线程(如通过Task.Run)的工作方式不同? - Why sequential call of AsyncLock within same (UI) thread doesn't work same way as for different threads (like via Task.Run)? 为什么继承不以我认为它应该工作的方式工作? - Why doesn't inheritance work the way I think it should work? 在关闭防火墙的同一子网上的两台计算机之间,WCF发现不起作用 - WCF discovery doesn't work between two computers on the same subnet with the firewall turned off
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM