SOAP 返回数据,但 C# 表示响应为空

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12223141/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 22:30:22  来源:igfitidea点击:

SOAP returns data, but C# says null response

c#xmlweb-servicessoappeoplesoft

提问by Aren Cambre

My C# app won't give me anything but null results from SOAP calls.

我的 C# 应用程序除了来自 SOAP 调用的空结果外,不会给我任何结果。

We have exposed some PeopleSoft ERP data with a SOAP web service.

我们已经使用 SOAP Web 服务公开了一些 PeopleSoft ERP 数据。

I am accessing this SOAP service from a Visual Studio 2012 ASP.NET C# app. I have a Service Reference named CampusDirectoryServicebuilt using the WSDL generated by the ERP.

我正在从 Visual Studio 2012 ASP.NET C# 应用程序访问此 SOAP 服务。我有一个名为CampusDirectoryService的服务引用,是使用 ERP 生成的 WSDL 构建的。

Here's the C# code:

这是 C# 代码:

var service = new CampusDirectoryService.TEST_PortTypeClient();
var input = new CampusDirectoryService.InputParameters();
input.First_Name = FirstNameBox.Text;
input.Last_Name = LastNameBox.Text;
var returnData = service.TEST_OP(input);

The problem is returnDatais always null. Through Wireshark, I confirmed that I am in fact getting a valid SOAP response with data. returnDatashould not be null.

问题returnData是始终为空。通过 Wireshark,我确认我实际上得到了一个有效的 SOAP 响应数据。returnData不应该为空。

I have confirmed correct valid results from the SOAP service through soapUI, too. Submitting the exact same SOAP request that .NET sends (I copied it out of Wireshark), I get expected results.

我也通过soapUI确认了来自 SOAP 服务的正确有效结果。提交 .NET 发送的完全相同的 SOAP 请求(我从 Wireshark 复制它),我得到了预期的结果。

Here's the SOAP request:

这是 SOAP 请求:

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <InputParameters xmlns="http://xmlns.oracle.com/Enterprise/Tools/schemas">
      <Last_Name xmlns="">cambre</Last_Name>
      <First_Name xmlns="">aren</First_Name>
    </InputParameters>
  </s:Body>
</s:Envelope>

Here's the SOAP response, with some internal data inside the ReturnIDelement obfuscated or removed:

这是 SOAP 响应,ReturnID元素中的一些内部数据被混淆或删除:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <root xmlns="http://peoplesoft.com/rootResponse">
         <ReturnID>
            <PRF_Name>Cambre,Aren</PRF_Name>
            <Camp_Email>[email protected]</Camp_Email>
         </ReturnID>
      </root>
   </soapenv:Body>
</soapenv:Envelope>

The return type of the TEST_OPmethod is CampusDirectoryService.rootReturnID[].

TEST_OP方法的返回类型是CampusDirectoryService.rootReturnID[].

Why is returnDataalways null?

为什么returnData总是为空?

UPDATEPer a comment, I validated the messages with soapUI. It's squawking on the response with this message:

更新根据评论,我使用soapUI 验证了消息。它对这条消息的响应发出了嘎嘎声:

line -1: Missing message part with name [{http://xmlns.oracle.com/Enterprise/Tools/schemas}root]

第 -1 行:缺少名称为 [{ http://xmlns.oracle.com/Enterprise/Tools/schemas}root] 的消息部分

Here's the XSD for the response:

这是响应的 XSD:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://xmlns.oracle.com/Enterprise/Tools/schemas" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="root">
    <xs:complexType>
      <xs:sequence>
        <xs:element maxOccurs="unbounded" name="ReturnID">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="PRF_Name" type="xs:string" />
              <xs:element name="Camp_Email" type="xs:string" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

Is the XSD supposed to validate what's inside soapenv:Body, or is it supposed to validate the entire response, including the soapenv:Envelopeand soapenv:Bodyelements? Looks like soapUI expects the XSD to validate the entire response, not just what's inside soapenv:Body.

XSD 应该验证里面的内容soapenv:Body,还是应该验证整个响应,包括soapenv:Envelopesoapenv:Body元素?看起来 soapUI 期望 XSD 验证整个响应,而不仅仅是里面的内容soapenv:Body

Here's the WSDL:

这是 WSDL:

<wsdl:definitions name="TEST.1" targetNamespace="http://xmlns.oracle.com/Enterprise/HCM/schemas/TEST.1" xmlns:U_IT_CAMDIR_REQUEST_MSG.VERSION_1="http://xmlns.oracle.com/Enterprise/Tools/schemas" xmlns:U_IT_CAMDIR_RESPONSE_MSG.VERSION_1="http://xmlns.oracle.com/Enterprise/Tools/schemas" xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://xmlns.oracle.com/Enterprise/HCM/schemas/TEST.1" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
   <wsp:UsagePolicy wsdl:Required="true"/>
   <plnk:partnerLinkType name="TEST_PartnerLinkType">
      <plnk:role name="TEST_Provider">
         <plnk:portType name="tns:TEST_PortType"/>
      </plnk:role>
   </plnk:partnerLinkType>
   <wsdl:types>
      <xsd:schema elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
         <xsd:import namespace="http://xmlns.oracle.com/Enterprise/Tools/schemas" schemaLocation="U_IT_CAMDIR_REQUEST_MSG.VERSION_1.xsd"/>
         <xsd:import namespace="http://xmlns.oracle.com/Enterprise/Tools/schemas" schemaLocation="U_IT_CAMDIR_RESPONSE_MSG.VERSION_1.xsd"/>
      </xsd:schema>
   </wsdl:types>
   <wsdl:message name="U_IT_CAMDIR_REQUEST_MSG.VERSION_1">
      <wsdl:documentation>People Directory</wsdl:documentation>
      <wsdl:part element="U_IT_CAMDIR_REQUEST_MSG.VERSION_1:InputParameters" name="parameter"/>
   </wsdl:message>
   <wsdl:message name="U_IT_CAMDIR_RESPONSE_MSG.VERSION_1">
      <wsdl:documentation>People Directory</wsdl:documentation>
      <wsdl:part element="U_IT_CAMDIR_RESPONSE_MSG.VERSION_1:root" name="parameter"/>
   </wsdl:message>
   <wsdl:portType name="TEST_PortType">
      <wsdl:operation name="TEST_OP">
         <wsdl:documentation>TEST</wsdl:documentation>
         <wsdl:input message="tns:U_IT_CAMDIR_REQUEST_MSG.VERSION_1" name="U_IT_CAMDIR_REQUEST_MSG.VERSION_1"/>
         <wsdl:output message="tns:U_IT_CAMDIR_RESPONSE_MSG.VERSION_1" name="U_IT_CAMDIR_RESPONSE_MSG.VERSION_1"/>
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="TEST_Binding" type="tns:TEST_PortType">
      <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="TEST_OP">
         <soap:operation soapAction="TEST_OP.v1" style="document"/>
         <wsp:Policy wsu:Id="UsernameTokenSecurityPolicyPasswordOptional" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsp:ExactlyOne>
               <wsp:All>
                  <wsse:SecurityToken wsp:Usage="wsp:Required" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
                     <wsse:TokenType>wsse:UserNameToken</wsse:TokenType>
                     <Claims>
                        <SubjectName MatchType="wsse:Exact"/>
                        <UsePassword wsp:Usage="wsp:Optional"/>
                     </Claims>
                  </wsse:SecurityToken>
               </wsp:All>
            </wsp:ExactlyOne>
         </wsp:Policy>
         <wsdl:input name="U_IT_CAMDIR_REQUEST_MSG.VERSION_1">
            <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
         </wsdl:input>
         <wsdl:output name="U_IT_CAMDIR_RESPONSE_MSG.VERSION_1">
            <soap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" use="literal"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="TEST">
      <wsdl:documentation>TEST</wsdl:documentation>
      <wsdl:port binding="tns:TEST_Binding" name="TEST_Port">
         <soap:address location="http://domainname.com/longurltoSOAPservicehere"/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

采纳答案by Daron Zwink

Ok, I think I found a solution to this exact same problem. I found to fix this, there were two main items that had to be configured properly.

好的,我想我找到了解决这个完全相同问题的方法。我发现要解决这个问题,必须正确配置两个主要项目。

  1. Make sure to set a namespace on the service (PeopleTools > Integration Broker > Integration Setup > Service). In mine, I used a namespace of:

    http://xmlns.oracle.com/Enterprise/EnterprisePortal/services
    
  2. It is very important how you create your schemas and the namespaces they use. Each schema requires a special namespace format and message format based on the way PeopleSoft returns the message. For mine, I used the following schemas:

    Example Request Message Schema:(The request message I used was IS_CL_COMPLETEPERCENTAGE_REQ.V1)

        <?xml version="1.0"?> 
        <xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/Enterprise/EnterprisePortal/services/IS_CL_COMPLETEPERCENTAGE_REQ.V1" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
          <xsd:element name="IS_CL_COMPLETEPERCENTAGE_REQ"> 
            <xsd:complexType> 
              <xsd:sequence> 
                <xsd:element name="USER_ID" type="xsd:string"/> 
                <xsd:element name="CHECKLIST_TYPE" type="xsd:string"/> 
                <xsd:element name="CHECKLIST_ID" type="xsd:string"/> 
                <xsd:element name="CHECKLIST_INSTANCE_ID" type="xsd:integer"/> 
              </xsd:sequence> 
            </xsd:complexType> 
          </xsd:element> 
        </xsd:schema>
    

    Example Response Message Schema:(The response message I used was IS_CL_COMPLETEPERCENTAGE_RES.V1)

        <?xml version="1.0"?> 
        <xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://peoplesoft.com/IS_CL_COMPLETEPERCENTAGE_RESResponse" xmlns:tns="http://peoplesoft.com/IS_CL_COMPLETEPERCENTAGE_RESResponse" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
          <xsd:element name="IS_CL_COMPLETEPERCENTAGE_RES"> 
            <xsd:complexType> 
              <xsd:sequence> 
                <xsd:element name="PERCENTCOMPLETE" type="xsd:integer"/> 
              </xsd:sequence> 
            </xsd:complexType> 
          </xsd:element> 
        </xsd:schema>
    
  1. 确保在服务上设置命名空间(PeopleTools > Integration Broker > Integration Setup > Service)。在我的中,我使用了以下命名空间:

    http://xmlns.oracle.com/Enterprise/EnterprisePortal/services
    
  2. 如何创建模式及其使用的命名空间非常重要。每个模式都需要基于 PeopleSoft 返回消息的方式的特殊命名空间格式和消息格式。对于我的,我使用了以下模式:

    示例请求消息架构:(我使用的请求消息是 IS_CL_COMPLETEPERCENTAGE_REQ.V1)

        <?xml version="1.0"?> 
        <xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://xmlns.oracle.com/Enterprise/EnterprisePortal/services/IS_CL_COMPLETEPERCENTAGE_REQ.V1" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
          <xsd:element name="IS_CL_COMPLETEPERCENTAGE_REQ"> 
            <xsd:complexType> 
              <xsd:sequence> 
                <xsd:element name="USER_ID" type="xsd:string"/> 
                <xsd:element name="CHECKLIST_TYPE" type="xsd:string"/> 
                <xsd:element name="CHECKLIST_ID" type="xsd:string"/> 
                <xsd:element name="CHECKLIST_INSTANCE_ID" type="xsd:integer"/> 
              </xsd:sequence> 
            </xsd:complexType> 
          </xsd:element> 
        </xsd:schema>
    

    示例响应消息架构:(我使用的响应消息是 IS_CL_COMPLETEPERCENTAGE_RES.V1)

        <?xml version="1.0"?> 
        <xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://peoplesoft.com/IS_CL_COMPLETEPERCENTAGE_RESResponse" xmlns:tns="http://peoplesoft.com/IS_CL_COMPLETEPERCENTAGE_RESResponse" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> 
          <xsd:element name="IS_CL_COMPLETEPERCENTAGE_RES"> 
            <xsd:complexType> 
              <xsd:sequence> 
                <xsd:element name="PERCENTCOMPLETE" type="xsd:integer"/> 
              </xsd:sequence> 
            </xsd:complexType> 
          </xsd:element> 
        </xsd:schema>
    

After I published my Web Service using this information, SoapUI validated both the request and response without an issue.

在我使用这些信息发布我的 Web 服务后,SoapUI 验证了请求和响应都没有问题。

Example SOAP Request Message:

示例 SOAP 请求消息

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:is="http://xmlns.oracle.com/Enterprise/EnterprisePortal/services/IS_CL_COMPLETEPERCENTAGE_REQ.V1" xmlns:sch="http://xmlns.oracle.com/Enterprise/Tools/schemas">
   <soapenv:Header/>
   <soapenv:Body>
      <is:IS_CL_COMPLETEPERCENTAGE_REQ>
         <is:USER_ID>999999</is:USER_ID>
         <is:CHECKLIST_TYPE>GRP</is:CHECKLIST_TYPE>
         <is:CHECKLIST_ID>NEW_HIRE_CHECKLIST</is:CHECKLIST_ID>
         <is:CHECKLIST_INSTANCE_ID>0</is:CHECKLIST_INSTANCE_ID>
      </is:IS_CL_COMPLETEPERCENTAGE_REQ>
   </soapenv:Body>
</soapenv:Envelope>

Example SOAP Response Message:

示例 SOAP 响应消息

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Body>
      <IS_CL_COMPLETEPERCENTAGE_RES xmlns="http://peoplesoft.com/IS_CL_COMPLETEPERCENTAGE_RESResponse">
         <PERCENTCOMPLETE>33</PERCENTCOMPLETE>
      </IS_CL_COMPLETEPERCENTAGE_RES>
   </soapenv:Body>
</soapenv:Envelope>

回答by Will

From Oracle The issue is resolved by Bug ID 11560861 in PT8.50.00

来自 Oracle 该问题已通过 PT8.50.00 中的 Bug ID 11560861 解决

In PT 8.50 Steps: A. Recreate the schema for the reply message: 1. Peopletools>Integration Broker>Integration Setup>Messages. 2. Choose the COMBO_CF_EDIT_REPLY message. 3. Select the check box "Include Namesapce". 4. Save.

在 PT 8.50 步骤: A. 重新创建回复消息的模式: 1. Peopletools>Integration Broker>Integration Setup>Messages。2. 选择 COMBO_CF_EDIT_REPLY 消息。3. 选中复选框“包括命名空间”。4. 保存。

B. Regenerate the WSDL: 1. Peopletools>Integration Broker>Web Services. 2. Choose the COMBO_CF_EDIT_REQUEST service operation. 3. Continue with the Provide Web Services wizard to generate the WSDL.

B. 重新生成 WSDL: 1. Peopletools>Integration Broker>Web Services。2. 选择 COMBO_CF_EDIT_REQUEST 服务操作。3. 继续使用提供 Web 服务向导生成 WSDL。

Prior to upgrading to 8.50 there are three workaround options: A. Modify the WSDL:
1. Generate the WSDL from PeopleTools and then save to file. 2. Update the WSDL file by modifying the reply to have the entry

在升级到 8.50 之前,有三个解决方法选项: A. 修改 WSDL:
1. 从 PeopleTools 生成 WSDL,然后保存到文件。2.通过修改回复来更新WSDL文件以包含条目

to replace the generated: xmlns="http://xmlns.oracle.com/Enterprise/FSCM/schema/COMBO_CF_EDIT_REPLYResponse">"

替换生成的: xmlns="http://xmlns.oracle.com/Enterprise/FSCM/schema/COMBO_CF_EDIT_REPLYResponse">"

  1. Then read the WSDL file back into the repository. Peopletools>Integration Broker>Web Services>Consume Web Services.

    OR B. Convert the rowset based messages to container/ part rowset messages.

  2. To create container/row set parts messages see: PeopleBook: PeopleSoft Integration Broker > Managing Messages>Managing Message Parts PeopleBook: PeopleSoft Integration Broker > Managing Messages>Managing Container Messages

  3. Modify the Service Operation to reference the Container Messasge.

  4. Then generate a new WSDL.
  5. Modify the Handler Peoplecode to utilize the methods of Parts message. See: PeopleBook: PeopleCode API Reference > Message Classes> %PART% methods
  1. 然后将 WSDL 文件读回存储库。Peopletools>Integration Broker>Web 服务>使用 Web 服务。

    或 B. 将基于行集的消息转换为容器/部分行集消息。

  2. 要创建容器/行集部件消息,请参阅:PeopleBook:PeopleSoft 集成代理 > 管理消息>管理消息部件 PeopleBook:PeopleSoft 集成代理 > 管理消息>管理容器消息

  3. 修改服务操作以引用容器消息。

  4. 然后生成一个新的 WSDL。
  5. 修改 Handler Peoplecode 以使用 Parts 消息的方法。请参阅:PeopleBook:PeopleCode API 参考 > 消息类 > %PART% 方法

OR C. Transform the outbound response messages via XSLT or PeopleCode to match the WSDL is another way to adjust the actual response xmlns to the expected value.

或 C. 通过 XSLT 或 PeopleCode 转换出站响应消息以匹配 WSDL 是将实际响应 xmlns 调整为预期值的另一种方法。