如何使用dotnet使用ColdFusion Web服务

时间:2012-03-09 01:36:21

标签: c# .net web-services soap coldfusion

我在SOAP和Web服务方面根本没有经验。我正在尝试从C#(.NET 4.0)调用ColdFusion Web服务。我正在使用svcutil.exe从WSDL生成代理。当我从SoapUI调用ListCases时,Web服务正常工作,但是当我从代理调用它时,我得到一个带有单个mapItem的映射,并且该mapItem具有null项和值。我猜这不起作用,因为WSDL不包含QueryBean的定义。如果这是问题,我会尝试让Web服务的作者添加定义,否则除了手动解析XML之外我还有其他选择吗?

<wsdl:definitions xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://syndication.v63" xmlns:intf="http://syndication.v63" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns1="http://rpc.xml.coldfusion" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" targetNamespace="http://syndication.v63">
  <!-- WSDL created by ColdFusion version 9,0,1,274733 -->
  <wsdl:types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://xml.apache.org/xml-soap">
      <import namespace="http://rpc.xml.coldfusion"/>
      <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
      <complexType name="mapItem">
        <sequence>
          <element name="key" nillable="true" type="xsd:anyType"/>
          <element name="value" nillable="true" type="xsd:anyType"/>
        </sequence>
      </complexType>
      <complexType name="Map">
        <sequence>
          <element maxOccurs="unbounded" minOccurs="0" name="item" type="apachesoap:mapItem"/>
        </sequence>
      </complexType>
    </schema>
    <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://rpc.xml.coldfusion">
      <import namespace="http://xml.apache.org/xml-soap"/>
      <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
      <complexType name="CFCInvocationException">
        <sequence/>
      </complexType>
    </schema>
  </wsdl:types>
  <wsdl:message name="ListCasesResponse">
    <wsdl:part name="ListCasesReturn" type="apachesoap:Map"/>
  </wsdl:message>
  <wsdl:message name="FolderDetailsResponse">
    <wsdl:part name="FolderDetailsReturn" type="apachesoap:Map"/>
  </wsdl:message>
  <wsdl:message name="ListBoxesRequest">
    <wsdl:part name="CaseDatabase" type="xsd:string"/>
    <wsdl:part name="Prefix" type="xsd:string"/>
  </wsdl:message>
  <wsdl:message name="ListFoldersRequest">
    <wsdl:part name="CaseDatabase" type="xsd:string"/>
    <wsdl:part name="Prefix" type="xsd:string"/>
    <wsdl:part name="Box" type="xsd:string"/>
  </wsdl:message>
  <wsdl:message name="CFCInvocationException">
    <wsdl:part name="fault" type="tns1:CFCInvocationException"/>
  </wsdl:message>
  <wsdl:message name="ListPrefixesRequest">
    <wsdl:part name="CaseDatabase" type="xsd:string"/>
  </wsdl:message>
  <wsdl:message name="ListFoldersResponse">
    <wsdl:part name="ListFoldersReturn" type="apachesoap:Map"/>
  </wsdl:message>
  <wsdl:message name="ListPrefixesResponse">
    <wsdl:part name="ListPrefixesReturn" type="apachesoap:Map"/>
  </wsdl:message>
  <wsdl:message name="FolderDetailsRequest">
    <wsdl:part name="CaseDatabase" type="xsd:string"/>
    <wsdl:part name="Prefix" type="xsd:string"/>
    <wsdl:part name="Box" type="xsd:string"/>
    <wsdl:part name="Folder" type="xsd:string"/>
  </wsdl:message>
  <wsdl:message name="ListCasesRequest"></wsdl:message>
  <wsdl:message name="ListBoxesResponse">
    <wsdl:part name="ListBoxesReturn" type="apachesoap:Map"/>
  </wsdl:message>
  <wsdl:portType name="Ricoh_syndication">
    <wsdl:operation name="ListCases">
      <wsdl:input message="impl:ListCasesRequest" name="ListCasesRequest"/>
      <wsdl:output message="impl:ListCasesResponse" name="ListCasesResponse"/>
      <wsdl:fault message="impl:CFCInvocationException" name="CFCInvocationException"/>
    </wsdl:operation>
    <wsdl:operation name="FolderDetails" parameterOrder="CaseDatabase Prefix Box Folder">
      <wsdl:input message="impl:FolderDetailsRequest" name="FolderDetailsRequest"/>
      <wsdl:output message="impl:FolderDetailsResponse" name="FolderDetailsResponse"/>
      <wsdl:fault message="impl:CFCInvocationException" name="CFCInvocationException"/>
    </wsdl:operation>
    <wsdl:operation name="ListFolders" parameterOrder="CaseDatabase Prefix Box">
      <wsdl:input message="impl:ListFoldersRequest" name="ListFoldersRequest"/>
      <wsdl:output message="impl:ListFoldersResponse" name="ListFoldersResponse"/>
      <wsdl:fault message="impl:CFCInvocationException" name="CFCInvocationException"/>
    </wsdl:operation>
    <wsdl:operation name="ListPrefixes" parameterOrder="CaseDatabase">
      <wsdl:input message="impl:ListPrefixesRequest" name="ListPrefixesRequest"/>
      <wsdl:output message="impl:ListPrefixesResponse" name="ListPrefixesResponse"/>
      <wsdl:fault message="impl:CFCInvocationException" name="CFCInvocationException"/>
    </wsdl:operation>
    <wsdl:operation name="ListBoxes" parameterOrder="CaseDatabase Prefix">
      <wsdl:input message="impl:ListBoxesRequest" name="ListBoxesRequest"/>
      <wsdl:output message="impl:ListBoxesResponse" name="ListBoxesResponse"/>
      <wsdl:fault message="impl:CFCInvocationException" name="CFCInvocationException"/>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="ricoh_syndication.cfcSoapBinding" type="impl:Ricoh_syndication">
    <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="ListCases">
      <wsdlsoap:operation soapAction=""/>
      <wsdl:input name="ListCasesRequest">
        <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:input>
      <wsdl:output name="ListCasesResponse">
        <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:output>
      <wsdl:fault name="CFCInvocationException">
        <wsdlsoap:fault encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" name="CFCInvocationException" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:fault>
    </wsdl:operation>
    <wsdl:operation name="FolderDetails">
      <wsdlsoap:operation soapAction=""/>
      <wsdl:input name="FolderDetailsRequest">
        <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:input>
      <wsdl:output name="FolderDetailsResponse">
        <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:output>
      <wsdl:fault name="CFCInvocationException">
        <wsdlsoap:fault encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" name="CFCInvocationException" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:fault>
    </wsdl:operation>
    <wsdl:operation name="ListFolders">
      <wsdlsoap:operation soapAction=""/>
      <wsdl:input name="ListFoldersRequest">
        <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:input>
      <wsdl:output name="ListFoldersResponse">
        <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:output>
      <wsdl:fault name="CFCInvocationException">
        <wsdlsoap:fault encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" name="CFCInvocationException" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:fault>
    </wsdl:operation>
    <wsdl:operation name="ListPrefixes">
      <wsdlsoap:operation soapAction=""/>
      <wsdl:input name="ListPrefixesRequest">
        <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:input>
      <wsdl:output name="ListPrefixesResponse">
        <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:output>
      <wsdl:fault name="CFCInvocationException">
        <wsdlsoap:fault encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" name="CFCInvocationException" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:fault>
    </wsdl:operation>
    <wsdl:operation name="ListBoxes">
      <wsdlsoap:operation soapAction=""/>
      <wsdl:input name="ListBoxesRequest">
        <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:input>
      <wsdl:output name="ListBoxesResponse">
        <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:output>
      <wsdl:fault name="CFCInvocationException">
        <wsdlsoap:fault encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" name="CFCInvocationException" namespace="http://syndication.v63" use="encoded"/>
      </wsdl:fault>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="Ricoh_syndicationService">
    <wsdl:port binding="impl:ricoh_syndication.cfcSoapBinding" name="ricoh_syndication.cfc">
      <wsdlsoap:address location="https://www2.delium.com/v6-3/syndication/ricoh_syndication.cfc"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>

和结果(我修改了它,以便有一个较短的数据列表,不包含机密信息)

<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:ListCasesResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:ns1="http://syndication.v63">
         <ListCasesReturn xsi:type="ns2:Map" xmlns:ns2="http://xml.apache.org/xml-soap">
            <item xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
               <key xsi:type="soapenc:string">RETURNCODE</key>
               <value xsi:type="soapenc:string">1</value>
            </item>
            <item>
               <key xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">RETURNTEXT</key>
               <value xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">Success (1)</value>
            </item>
            <item>
               <key xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">OUTPUTS</key>
               <value xsi:type="ns2:Map">
                  <item xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
                     <key xsi:type="soapenc:string">QCASES</key>
                     <value xsi:type="ns3:QueryBean" xmlns:ns3="http://rpc.xml.coldfusion">
                        <columnList soapenc:arrayType="xsd:string[2]" xsi:type="soapenc:Array">
                           <columnList xsi:type="xsd:string">CASENAME</columnList>
                           <columnList xsi:type="xsd:string">CASEDATABASE</columnList>
                        </columnList>
                        <data soapenc:arrayType="xsd:anyType[][35]" xsi:type="soapenc:Array">
                           <data soapenc:arrayType="xsd:anyType[2]" xsi:type="soapenc:Array">
                              <data xsi:type="soapenc:string">test1</data>
                              <data xsi:type="soapenc:string">test2</data>
                           </data>
                        </data>
                     </value>
                  </item>
                  <item>
                     <key xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">REMOTEIPADDRESS</key>
                     <value xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">219.89.202.100</value>
                  </item>
               </value>
            </item>
         </ListCasesReturn>
      </ns1:ListCasesResponse>
   </soapenv:Body>
</soapenv:Envelope>

1 个答案:

答案 0 :(得分:2)

是的,看起来WSDL没有定义ns3:QueryBean类型,代理也无法将其反序列化为该类型;最好的选择是要求webservice的作者为您提供所有必要的类型。它们必须已经在它们的末尾定义了所有类型,因此可能更容易获得具有类型定义的XSD或包含类型的WSDL。

如果它们动态生成随机类型(例如:QueryBean,Foo,Foobar)等,那么你可能会运气不好,在这种情况下除了手动遍历xml之外别无他法。

相关问题