2013-05-29 45 views
10

Tôi đang cố gắng triển khai một Dịch vụ Web chạy trên hệ thống SAP PI. WSDL tôi trông như thế này:PHP SoapClient: Không cần thiết WSDL mở rộng

<?xml version="1.0" encoding="UTF-8"?> 
<wsdl:definitions name="request_SO" targetNamespace="http://company.ch/orstest/jason_test" xmlns:p1="http://company.ch/orstest/jason_test" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"> 
    <wsdl:documentation/> 
    <wsp:UsingPolicy wsdl:required="true"/> 
    <wsp:Policy wsu:Id="OP_request_SO"/> 
    <wsdl:types> 
     <xsd:schema targetNamespace="http://company.ch/orstest/jason_test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://company.ch/orstest/jason_test"> 
      <xsd:element name="request" type="request"/> 
      <xsd:element name="response" type="response"/> 
      <xsd:complexType name="request"> 
       <xsd:annotation> 
        <xsd:appinfo source="http://sap.com/xi/VersionID">a8b7948ac2e211e2b2380000001f0d6a</xsd:appinfo> 
       </xsd:annotation> 
       <xsd:sequence> 
        <xsd:element name="body" type="xsd:string"/> 
       </xsd:sequence> 
      </xsd:complexType> 
      <xsd:complexType name="response"> 
       <xsd:annotation> 
        <xsd:appinfo source="http://sap.com/xi/VersionID">bf49af09c36c11e299790000001f0d6a</xsd:appinfo> 
       </xsd:annotation> 
       <xsd:sequence> 
        <xsd:element name="body" type="xsd:string"/> 
       </xsd:sequence> 
      </xsd:complexType> 
     </xsd:schema> 
    </wsdl:types> 
    <wsdl:message name="request"> 
     <wsdl:documentation/> 
     <wsdl:part name="request" element="p1:request"/> 
    </wsdl:message> 
    <wsdl:message name="response"> 
     <wsdl:documentation/> 
     <wsdl:part name="response" element="p1:response"/> 
    </wsdl:message> 
    <wsdl:portType name="request_SO"> 
     <wsdl:documentation/> 
     <wsdl:operation name="request_SO"> 
      <wsdl:documentation/> 
      <wsp:Policy> 
       <wsp:PolicyReference URI="#OP_request_SO"/> 
      </wsp:Policy> 
      <wsdl:input message="p1:request"/> 
      <wsdl:output message="p1:response"/> 
     </wsdl:operation> 
    </wsdl:portType> 
    <wsdl:binding name="request_SOBinding" type="p1:request_SO"> 
     <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/> 
     <wsdl:operation name="request_SO"> 
      <soap:operation soapAction="http://sap.com/xi/WebService/soap1.1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/> 
      <wsdl:input> 
       <soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/> 
      </wsdl:input> 
      <wsdl:output> 
       <soap:body use="literal" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/> 
      </wsdl:output> 
     </wsdl:operation> 
    </wsdl:binding> 
    <wsdl:service name="request_SOService"> 
     <wsdl:port name="HTTP_Port" binding="p1:request_SOBinding"> 
      <soap:address location="http://qa1100ap601.company.car.web:50000/XISOAPAdapter/MessageServlet?senderParty=&amp;senderService=BS_ORS&amp;receiverParty=&amp;receiverService=&amp;interface=request_SO&amp;interfaceNamespace=http://company.ch/orstest/jason_test" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/> 
     </wsdl:port> 
     <wsdl:port name="HTTPS_Port" binding="p1:request_SOBinding"> 
      <soap:address location="https://qas.soa.subcompany.company.ch/XISOAPAdapter/MessageServlet?senderParty=&amp;senderService=BS_ORS&amp;receiverParty=&amp;receiverService=&amp;interface=request_SO&amp;interfaceNamespace=http://company.ch/orstest/jason_test" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"/> 
     </wsdl:port> 
    </wsdl:service> 
</wsdl:definitions> 

file PHP của tôi trông như thế này (chẳng khác gì ở trong đó hiện tại):

<?php 
$client = new SoapClient('test.wsdl'); 
?> 

Khi tôi chạy kịch bản của tôi, tôi nhận được lỗi sau ném :

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Unknown required WSDL extension 'http://schemas.xmlsoap.org/ws/2004/09/policy' in /srv/www/htdocs/wsdl.php:2 Stack trace: #0 /srv/www/htdocs/wsdl.php(2): SoapClient->SoapClient('test.wsdl') #1 {main} thrown in /srv/www/htdocs/wsdl.php on line 2 

tôi đã cố gắng tìm kiếm các lỗi trên google và StackOverflow, và cũng có thể kiểm tra các ý kiến ​​trên php.net, nhưng tôi dường như không thể tìm ra những gì tôi sẽ phải thay đổi để có được điều này Dịch vụ đang chạy. Tôi cũng đã cố gắng mở URL mở rộng WSDL, dường như nó tồn tại.

Ai đó có thể ném cho tôi một cái xương ở đây không? Tôi đã cố gắng loại bỏ các URL mở rộng, có kết quả trong các lỗi sau:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Unexpected WSDL element <UsingPolicy> in /srv/www/htdocs/wsdl.php:2 Stack trace: #0 /srv/www/htdocs/wsdl.php(2): SoapClient->SoapClient('test.wsdl') #1 {main} thrown in /srv/www/htdocs/wsdl.php on line 2 

Trả lời

16

Giải pháp duy nhất tôi có thể nghĩ ra vào thời điểm này là để cập nhật thẻ UsingPolicy của bạn:

Thay đổi tag:

<wsp:UsingPolicy wsdl:required="true"/> 

này:

<wsp:UsingPolicy wsdl:required="false"/> 
+2

Rất tuyệt, lỗi đã biến mất ngay bây giờ :) Bây giờ tôi có thể thử dịch vụ :) – Ahatius

+0

Rất vui! Rất vui được trợ giúp. –

14

Đây không phải là thực sự là câu trả lời đúng trong một môi trường SAP. Trong URL của bạn cho WSDL, bạn sẽ thấy /ws_policy/ - thay đổi điều này thành /standard/ và bạn sẽ có thể sử dụng lớp PHP SoapClient để tiêu thụ dịch vụ web mà không phải duy trì bản sao sửa đổi cục bộ của WSDL. Bạn có thể thấy giống nhau trên một blog SAP here (có thể cần đăng nhập).

+0

Tôi đã có chính xác vấn đề này với dịch vụ web SAP và câu trả lời của bạn đã lưu ngày của tôi! – Shmarkus

3

For new versions the URL is not containing anymore the "ws_policy" instead there is a 0 (standard)or 1 (policy)

Example:

....wsdl/flv_10002A111AD1/bndg_url/.... (ws_policy)

....wsdl/flv_10002A101AD1/bndg_url/.... (standard)

Tín dụng cho Rafa Martinez

+0

Cảm ơn câu trả lời tuyệt vời này! Bạn đã tiết kiệm cho tôi giờ! – Sonson123

0

Có vẻ là một lỗi trong PHP SOAPServer, hoặc một khả năng tương thích phần mở rộng mất tích, và nó đã không được giải quyết chưa, ít nhất là trong PHP 5.6.31.

Giải pháp duy nhất tôi có thể tìm được để thiết lập cần thiết UsingPolicy-false, như đề xuất trong việc ứng phó được chấp nhận:

<wsp:UsingPolicy wsdl:required="false" /> 

Nhưng khách hàng có thể truy cập dịch vụ SOAP mà không xác thực, đây là một vấn đề an ninh nghiêm trọng. Vì vậy, tôi đã cố gắng kiểm tra thủ công rằng dữ liệu bảo mật được gửi bởi máy khách.

$soapEnvelope = new DOMDocument(); 
$soapEnvelope->loadXML(file_get_contents("php://input"), LIBXML_DTDATTR); 
$wsseNamespace = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"; 

if ($soapEnvelope->getElementsByTagNameNS($wsseNamespace, 'Security')->length == 0) { 
    throw new SoapFault("auth", 'Authentication error - Missing wsse:Security node'); 
} 

if ($soapEnvelope->getElementsByTagNameNS($wsseNamespace, 'UsernameToken')->length == 0) { 
    throw new SoapFault("auth", 'Authentication error - Missing UsernameToken node'); 
} 

if ($soapEnvelope->getElementsByTagNameNS($wsseNamespace, 'Username')->length == 0) { 
    throw new SoapFault("auth", 'Authentication error - Missing Username node'); 
} 

if ($soapEnvelope->getElementsByTagNameNS($wsseNamespace, 'Password')->length == 0) { 
    throw new SoapFault("auth", 'Authentication error - Missing Password node'); 
} 

// SOAPServer handle requests method 
$server->handle(); 

Đó là mẹo vặt nhưng nó hoạt động.