[英]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.