首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >soap complexType没有数据

soap complexType没有数据
EN

Stack Overflow用户
提问于 2014-09-29 20:59:12
回答 2查看 162关注 0票数 0

使用ColdFusion 9,我创建了一个组件作为我正在开发的WinForm应用程序的SOAP服务。当我调用通过SOAP返回自定义组件的远程函数时,不返回任何数据。如果我在另一种方法中序列化到Json字符串,在客户端应用程序中反序列化,则需要做一些工作。我想避免这一步。在我缺少的组件/函数中是否有参数,或者这是CF9中的一个bug?

我还没有尝试过其他版本的ColdFusion。我在Railo上运行了相同的代码,并得到了预期的数据。

当我通过web浏览器查看该方法时,我会看到以选定的返回格式返回的数据。

浏览器返回:

{"stringField":"Test Value","dateField":"September, 29 2014 15:35:16"}

SoapUI返回:

代码语言:javascript
复制
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns1:getComplexDataObjResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://complexdataservice">
         <getComplexDataObjReturn xsi:type="ns1:ComplexData">
            <dateField xsi:type="xsd:dateTime" xsi:nil="true"/>
            <stringField xsi:type="xsd:string" xsi:nil="true"/>
         </getComplexDataObjReturn>
      </ns1:getComplexDataObjResponse>
   </soapenv:Body>
</soapenv:Envelope>

testService.cfc

代码语言:javascript
复制
<cfcomponent output="false">

    <cffunction name="getComplexData" access="remote" output="false" returntype="String" hint="temporary workaround">
        <cfreturn serializejson(getComplexDataObj()) />
    </cffunction>

    <cffunction name="getComplexDataObj" access="remote" output="false" returnformat="json" returntype="complexData">
        <cfreturn new complexData("Test Value", Now()) />
    </cffunction>

</cfcomponent>

complexData.cfc

代码语言:javascript
复制
<cfcomponent output="false">

    <cfproperty name="stringField" type="string" />
    <cfproperty name="dateField" type="date" />

    <cffunction name="init" access="public" output="false">
        <cfargument name="Field1" required="true" type="string">
        <cfargument name="Field2" required="true" type="date">
        <cfset stringField = arguments.Field1>
        <cfset dateField = arguments.Field2>
        <cfreturn />
    </cffunction>

</cfcomponent>

在铁道,我得到:

代码语言:javascript
复制
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns1:getComplexDataObjResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://complexDataService">
         <getComplexDataObjReturn href="#id0"/>
      </ns1:getComplexDataObjResponse>
      <multiRef id="id0" soapenc:root="0" soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xsi:type="ns2:complexDataService.complexData" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns2="http://rpc.xml.coldfusion">
      <dateField xsi:type="xsd:dateTime">2014-09-29T20:06:26.420Z</dateField>
         <stringField xsi:type="xsd:string">Test Value</stringField>
      </multiRef>
   </soapenv:Body>
</soapenv:Envelope>
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-10-03 21:39:04

我弄明白了ColdFusion在做什么。我发现SOAP序列化只会将组件属性从组件的this范围中提取出来,而不会从variables作用域中提取出来。

我将组件重新加工成以下格式。注意,我只将字符串参数复制到this范围中。此外,为了在非SOAP请求上保持匹配JSON,我必须确保在this作用域变量名上使用struct符号。我仍然不确定我是否会重新工作我的所有组件,并可能继续依赖其他函数,因为访问器不操作通过SOAP请求返回的数据。

代码语言:javascript
复制
<cfcomponent output="false" accessors="true">

    <cfproperty name="stringField" type="string" required="true" />
    <cfproperty name="dateField" type="date" required="true"  />

    <cffunction name="init" access="public" output="false">
        <cfargument name="Field1" required="true" type="string">
        <cfargument name="Field2" required="true" type="date">
        <cfset setStringField(arguments.Field1)>
        <cfset setDateField(arguments.Field2)>
        <cfset this["StringField"] = getStringField()>
        <cfreturn />
    </cffunction>

</cfcomponent>

这为我提供了一个带有空日期时间的SOAP包,以及在我的getComplexDataObj函数中输入的测试字符串。

代码语言:javascript
复制
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <ns1:GetComplexDataObjResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://complexdataservice">
         <GetComplexDataObjReturn xsi:type="ns1:ComplexData">
            <dateField xsi:type="xsd:dateTime" xsi:nil="true"/>
            <stringField xsi:type="xsd:string">Test Value</stringField>
         </GetComplexDataObjReturn>
      </ns1:GetComplexDataObjResponse>
   </soapenv:Body>
</soapenv:Envelope>    
票数 0
EN

Stack Overflow用户

发布于 2014-09-30 01:21:58

不确定是ColdFusion bug还是.Net。我也经历过同样的问题。我的工作是改变组件style=“文档”而不是RPC。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26108807

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档