1

SUM:我最终不得不手动形成 XML。我还必须创建一个操作并使用它的 send(); 方法,而不仅仅是做类似 WebService.MyServiceFunction(); - 不知道为什么会这样。

我发送请求如下:

            var xm:XML =
                <SetPropertiesForCurrentUser xmlns="http://asp.net/ApplicationServices/v200">
                    <values xmlns:d4p1="http://schemas.microsoft.com/2003/10/Serialization/Arrays" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                        <d4p1:KeyValueOfstringanyType>
                            <d4p1:Key>{obj.Key}</d4p1:Key>
                            <d4p1:Value xmlns:d6p1="http://www.w3.org/2001/XMLSchema" i:type="d6p1:string">{obj.Value}</d4p1:Value>
                        </d4p1:KeyValueOfstringanyType>
                    </values>
                </SetPropertiesForCurrentUser>;

            var profileService:WebService = new WebService();
            profileService.useProxy = false;
            profileService.loadWSDL(url);

            var o:Operation = profileService.SetPropertiesForCurrentUser;
            o.send(xm);

这是我的场景:

我有 ASP.NET Web 服务来处理身份验证、用户角色和用户配置文件(准确地说是默认的 ASP.NET AuthenticationService、RoleService 和 ProfileService)。

因此,从我的 Flex Web 应用程序中,我能够成功调用 ASP.NET 服务。例如,这样的事情可以正常工作:

var profileService:WebService = new WebService();
profileService.useProxy = false;
profileService.GetAllPropertiesForCurrentUser.addEventListener("result",getAllPropertiesForCurrentUser_EventHandler);
profileService.addEventListener("fault",getAllPropertiesForCurrentUserFault_EventHandler);
profileService.loadWSDL(url);
profileService.GetAllPropertiesForCurrentUser();

当我需要将 Dictionary 对象传递给服务上的另一个函数 (SetPropertiesForCurrentUser) 时,我遇到了麻烦。.NET 服务要求这种类型的值:

System.Collections.Generic.IDictionary(字符串,对象)

以下是我的 ASP.NET 服务的 web.config 条目中的两个相关条目:

    <properties>
        <clear/>
        <add name="coordinateFormat" />
    </properties>
...
    <profileService enabled="true"
      readAccessProperties="coordinateFormat"
      writeAccessProperties="coordinateFormat"/>

因此,在将来自 Silverlight 应用程序的 SOAP 请求(按预期工作)放在一起后,我将其缩小到发送到 SOAP 处理程序的 XML 请求的差异:

来自 Flex:

<tns:Value>DMS</tns:Value>

来自银光:

<d4p1:Value xmlns:d6p1="http://www.w3.org/2001/XMLSchema" i:type="d6p1:string">DMS</d4p1:Value>

如果我接受 Flex 生成的请求,用 Fiddler 捕获它,修改那一行以包含“type”命名空间——它可以工作。

任何人都知道如何将该名称空间添加到从 Actionscript 传递给 SOAP 处理程序的变量上?这是我发送 SetPropertiesForCurrentUser 函数的代码:

var obj:Object = {};
obj["Key"] = "coordinateFormat";
obj["Value"] = DMS;

var profileService:WebService = new WebService();
profileService.useProxy = false;
profileService.SetPropertiesForCurrentUser.addEventListener("result",setPropertiesForCurrentUser_EventHandler);
profileService.addEventListener("fault",setPropertiesForCurrentUserFault_EventHandler);
profileService.loadWSDL(url);
profileService.SetPropertiesForCurrentUser(new ArrayCollection([obj]),false);

谢谢,乔什

4

1 回答 1

0

使用的默认 SOAPEncoder 在其功能上有所限制(例如不包括您上面提到的 type 属性)。幸运的是,有一种方法可以通过编写自己的编码器来控制它。

在 adobe 上查看此链接(阅读有关使用自定义 Web 服务序列化的部分)Adob​​e 网站上的链接

于 2012-11-27T17:05:55.680 回答