1

使用 ASP.NET WebServices,默认情况下您不能传递任何 IDictionary 对象,因为不支持 IDictionaries 的 xml 序列化。我找到了各种序列化字典的方法http://weblogs.asp.net/pwelter34/archive/2006/05/03/444961.aspx,http://blogs.msdn.com/psheill/archive/2005/04 /09/406823.aspx , http://www.mattberther.com/2004/06/14/serializing-an-idictionary-object/)但是,我找不到任何方法可以将它连接到 Asp.NET 网络中方法。

有没有办法将它连接起来,以便我可以将 IDictionaries 与 WebMethods 一起使用?

4

2 回答 2

0

取决于您如何调用这些方法,我们将 .net 2.0 方法与“Web 引用”一起使用,您会注意到 WSDL 生成的类是部分的,我们创建了一个(Web 引用名称).cs 文件并具有以下内容:


public partial class WebReferenceName : System.Web.Services.Protocols.SoapHttpClientProtocol 
{
    // Overload the WSDL generated method that only takes a simple array
    public ReturnType MethodName(List  collection)
    {
        // redirect the call to the wsdl generated method with the appropriate parameters
        return this.MethodName(collection.ToArray());
    }
}

重载将允许您使用任一类型的集合调用方法名称

在 Web 服务端,您可以从简单的集合转换回更强大的集合,很可能使用更强大的集合 ctor。其中一个 ctor 可能会使用一个简单的集合。

于 2009-02-12T18:23:22.260 回答
0

问题是 - 你想在哪里传递字典?如果您只是想教您的服务如何序列化字典,那么在您的字典类上实现 IXmlSerializable 接口,并按照您的喜好对其进行序列化。

问题将出在客户端上。Java 客户端应该如何反序列化您发送的内容?就此而言,.NET 客户端如何知道如何做到这一点?当使用旧的 ASMX Web 服务让客户端做一些特别的事情时,没有好的方法。这是发明 WCF 的众多原因之一。

于 2009-02-14T18:54:20.263 回答