1

我想用 SAP 的函数创建一个 RFC。我从这个函数生成了一个 SAP 数据源。当我去这个地址: http: //xxx.xxx.com :8000/sap/bc/soap/wsdl11?sap-client=200&services=ZTEST我有这个页面:

<?xml version="1.0" encoding="UTF-8"?>  
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:s0="urn:sap-com:document:sap:rfc:functions" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" targetNamespace="urn:sap-com:document:sap:rfc:functions">  

  <types>  

    <xsd:schema targetNamespace="urn:sap-com:document:sap:rfc:functions">  
      <xsd:element name="ZTEST">  
        <xsd:complexType>  
          <xsd:all>  
            <xsd:element name="RESULT">  
              <xsd:complexType>  
                <xsd:sequence>  
                  <xsd:element name="item" minOccurs="0" maxOccurs="unbounded" type="s0:PA0105">  
                  </xsd:element>  
                </xsd:sequence>  
              </xsd:complexType>  
            </xsd:element>  
          </xsd:all>  
        </xsd:complexType>  
      </xsd:element>  
      <xsd:element name="ZTEST.Response">  
        <xsd:complexType>  
          <xsd:all>  
            <xsd:element name="RESULT">  
              <xsd:complexType>  
                <xsd:sequence>  
                  <xsd:element name="item" minOccurs="0" maxOccurs="unbounded" type="s0:PA0105">  
                  </xsd:element>  
                </xsd:sequence>  
              </xsd:complexType>  
            </xsd:element>  
          </xsd:all>  
        </xsd:complexType>  
      </xsd:element>  
      <xsd:complexType name="PA0105">  
        <xsd:sequence>  
          <xsd:element name="MANDT" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="3">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="PERNR" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="8">  
                </xsd:maxLength>  
                <xsd:pattern value="\d*">  
                </xsd:pattern>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="SUBTY" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="4">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="OBJPS" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="2">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="SPRPS" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="1">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="ENDDA" minOccurs="0" type="s0:date">  
          </xsd:element>  
          <xsd:element name="BEGDA" minOccurs="0" type="s0:date">  
          </xsd:element>  
          <xsd:element name="SEQNR" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="3">  
                </xsd:maxLength>  
                <xsd:pattern value="\d*">  
                </xsd:pattern>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="AEDTM" minOccurs="0" type="s0:date">  
          </xsd:element>  
          <xsd:element name="UNAME" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="12">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="HISTO" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="1">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="ITXEX" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="1">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="REFEX" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="1">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="ORDEX" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="1">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="ITBLD" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="2">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="PREAS" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="2">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="FLAG1" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="1">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="FLAG2" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="1">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="FLAG3" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="1">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="FLAG4" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="1">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="RESE1" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="2">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="RESE2" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="2">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="GRPVL" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="4">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="USRTY" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="4">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="USRID" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="30">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
          <xsd:element name="USRID_LONG" minOccurs="0">  
            <xsd:simpleType>  
              <xsd:restriction base="xsd:string">  
                <xsd:maxLength value="241">  
                </xsd:maxLength>  
              </xsd:restriction>  
            </xsd:simpleType>  
          </xsd:element>  
        </xsd:sequence>  
      </xsd:complexType>  
      <xsd:simpleType name="date">  
        <xsd:restriction base="xsd:string">  
          <xsd:maxLength value="10">  
          </xsd:maxLength>  
          <xsd:pattern value="....-..-..">  
          </xsd:pattern>  
        </xsd:restriction>  
      </xsd:simpleType>  
    </xsd:schema>  
  </types>  
  <message name="ZTESTInput">  
    <part name="parameters" element="s0:ZTEST">  
    </part>  
  </message>  
  <message name="ZTESTOutput">  
    <part name="parameters" element="s0:ZTEST.Response">  
    </part>  
  </message>  
  <portType name="ZTESTPortType">  
    <operation name="ZTEST">  
      <input message="s0:ZTESTInput">  
      </input>  
      <output message="s0:ZTESTOutput">  
      </output>  
    </operation>  
  </portType>  
  <binding name="ZTESTBinding" type="s0:ZTESTPortType">  
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http">  
    </soap:binding>  
    <operation name="ZTEST">  
      <soap:operation soapAction="http://www.sap.com/ZTEST">  
      </soap:operation>  
      <input>  
        <soap:body use="literal">  
        </soap:body>  
      </input>  
      <output>  
        <soap:body use="literal">  
        </soap:body>  
      </output>  
    </operation>  
  </binding>  
  <service name="ZTESTService">  
    <documentation>  
      SAP Service ZTEST via SOAP</documentation>  
    <port name="ZTESTPortType" binding="s0:ZTESTBinding">  
      <soap:address location="http://***.***.com:8000/sap/bc/soap/rfc">  
      </soap:address>  
    </port>  
  </service>  
</definitions> 

我创建了一个 Javascript 函数,它发送这样的 post 请求:

var webServiceURL = 'http://xxx.xxx.com:8000/sap/bc/soap/wsdl11?sap-client=200&services=ZTEST';  
function createSoapEnvelope(contents) {  
    return '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" ' +  
      'SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">' +  
      '<SOAP-ENV:Body>' + contents + '</SOAP-ENV:Body></SOAP-ENV:Envelope>';  
}  

function HelloWorld() {  
    var message = createSoapEnvelope("<ZTEST/>");  
    $.ajax({  
        url: webServiceURL,   
        type: "POST",  
        dataType: "xml",   
        data: message,   
        async: false,  
        contentType: "text/xml; charset=\"utf-8\"",  
        success: OnSuccess,   
        processData: false,  
        error: OnError  
    });  

    return false;  
}  

function OnSuccess(data, status) {  
    alert(data.d);  
}  

function OnError(request, status, error) {  
    alert('error');  
}  

HelloWorld();  

当我运行代码时,我停留在描述上。我应该有一个用户列表。

你有解决办法吗?

谢谢!

编辑 1

当我去http://xxx.xxx.com:8000/sap/bc/srt/wsdl/srvc_%5Bguid%5D/wsdl11/allinone/ws_policy/document?sap-client=200

我有这个 :

<soap:Envelope>
  <soap:Body>
    <soap:Fault>
      <faultcode>
        soap:Server</faultcode>
      <faultstring>
        No service definition, interface name, or binding specified</faultstring>
      <detail>
        <slibfault:timestamp>
          Tue, 23 Oct 2012 12:06:02 GMT</slibfault:timestamp>
        <slibfault:exception>
          <slibfault:text>
            No service definition, interface name, or binding specified</slibfault:text>
          <slibfault:position program="CL_SRT_WSP_WSDL_HANDLER_HTTP==CP" include="CL_SRT_WSP_WSDL_HANDLER_HTTP==CM002" line="353 "/>
        </slibfault:exception>
      </detail>
    </soap:Fault>
  </soap:Body>
</soap:Envelope>

当我去这里时:http: //xxx.xxx.com :8000/sap/bc/srt/rfc/sap/ZTEST/200/ztest/binding我有空白页。

在 soamanager 中,当我选择我的 web 服务时,我在配置中有一行:

  • 服务:中测
  • 端点:ZTEST
  • 状态 : 活跃
  • 创建类型:手动创建
4

1 回答 1

1

看起来您发布到错误的 URI,而且我认为正文也不正确。
由于我无法确定适合您的正确值,因此我创建了一个类似的测试服务。一旦您看到我在工作服务上使用的 URI 和消息,也许您就能找到错误。
我创建了一个ZTESTRFC,它只返回一个message包含 string 的参数,从中Hello, World!生成一个 SOAP 服务,并为它创建一个与soamanager事务的绑定(也许您忘记了最后一步?)。结果如下:

WSDL URI:http://sapserver/sap/bc/srt/wsdl/srvc_[guid]/wsdl11/allinone/ws_policy/document?sap-client=200

WSDL 指定以下绑定 URI:http://sapserver/sap/bc/srt/rfc/sap/ztest/200/ztest/binding
http://sapserver/sap/bc/srt/rfc/sap/ztest/200/ztest/binding

向具有以下正文的任一绑定 URI发送 POST 请求(Content-Type text/xml)会返回预期结果:

<?xml version="1.0" encoding="UTF-8" ?>
<SOAP-ENV:Envelope
 xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <SOAP-ENV:Header>
        <sapsess:Session xmlns:sapsess="http://www.sap.com/webas/630/soap/features/session/">
            <enableSession>true</enableSession>
        </sapsess:Session>
    </SOAP-ENV:Header>
    <SOAP-ENV:Body>
        <ns1:Ztest xmlns:ns1='urn:sap-com:document:sap:soap:functions:mc-style'></ns1:Ztest>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>
于 2012-10-22T19:58:58.503 回答