简体   繁体   English

向SOAP WSDL发送请求

[英]Sending a request to SOAP WSDL

I want to create a RFC with from a SAP's function. 我想从SAP函数创建RFC。 I generated a SAP data source from this function. 我从此函数生成了一个SAP数据源。 When I go to this address : http://xxx.xxx.com:8000/sap/bc/soap/wsdl11?sap-client=200&services=ZTEST i have this page : 当我转到此地址时: 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> 

I created a Javascript function which send a post request like this : 我创建了一个Javascript函数,该函数发送如下发布请求:

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();  

When I run the code I stay on the description. 当我运行代码时,将停留在描述上。 I should have a list of users. 我应该有一个用户列表。

Doy you have a solution? 你有解决办法吗?

Thanks! 谢谢!

Edit 1 编辑1

When I go to http://xxx.xxx.com:8000/sap/bc/srt/wsdl/srvc_%5Bguid%5D/wsdl11/allinone/ws_policy/document?sap-client=200 当我转到http://xxx.xxx.com:8000/sap/bc/srt/wsdl/srvc_%5Bguid%5D/wsdl11/allinone/ws_policy/document?sap-client=200

I have this : 我有这个 :

<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>

When I go here : http://xxx.xxx.com:8000/sap/bc/srt/rfc/sap/ZTEST/200/ztest/binding i have blank page. 当我去这里: http : //xxx.xxx.com : 8000/sap/bc/srt/rfc/sap/ZTEST/200/ztest/binding我有空白页。

In soamanager, when I select my webservice, I have a line in configuration with : 在soamanager中,当我选择Web服务时,在配置中有一行:

  • Service : ZTEST 服务:ZTEST
  • Endpoints : ZTEST 端点:ZTEST
  • State : Active 状态:有效
  • Creation Type : Manually created 创建类型:手动创建

It looks like you're posting to the wrong URI, and I think the body is not correct either. 看来您发布到了错误的URI,而且我认为正文也不正确。
Since I cannot determine what the correct values should be for you, I've created a similar test service. 由于无法确定正确的值适合您,因此我创建了类似的测试服务。 Maybe you'll be able to find the error once you see the URI's and message I'm using on a working service. 看到我正在使用的服务上使用的URI和消息后,也许您将能够找到错误。
I've created a ZTEST RFC which simply returns a parameter message which contains the string Hello, World! 我创建了一个ZTEST RFC,它仅返回包含字符串Hello, World!的参数message Hello, World! , generated a SOAP service from it, and created a binding for it with the soamanager transaction (perhaps you forgot this last step?). ,从中生成一个SOAP服务,并使用soamanager事务为其创建一个绑定(也许您忘记了最后一步?)。 The results are as follows: 结果如下:

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/wsdl/srvc_[guid]/wsdl11/allinone/ws_policy/document?sap-client=200

The WSDL specifies the following binding URI's: http://sapserver/sap/bc/srt/rfc/sap/ztest/200/ztest/binding WSDL指定以下绑定URI: http://sapserver/sap/bc/srt/rfc/sap/ztest/200/ztest/binding
http://sapserver/sap/bc/srt/rfc/sap/ztest/200/ztest/binding

Sending a POST request (Content-Type text/xml ) to either of those binding URI's with the following body returns the expected result: 将POST请求(Content-Type text/xml )发送到具有以下正文的那些绑定URI之一将返回预期结果:

<?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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM