SOAP服务器:需要在没有SOAP Envelope的情况下返回SOAP响应

时间:2014-07-05 06:48:21

标签: php web-services soap wsdl

我正在用PHP开发SOAP Sever。 特殊要求此服务器应该使用SOAP Envelop接收请求,但在返回请求时,它不应包含任何soap信封。

请求看起来像这样:

<?xml version="1.0"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://www.w3.org/2001/12/soap-envelope"
SOAP-ENV:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
  <SOAP-ENV:Body xmlns:m="http://www.xyz.org/quotations">
    <GetDetails>
      <UserID>1<UserID>
    </GetDetails>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

响应应如下所示:

<UserDetails>
    <fame>ABC</fname>
    <lame>XYZ</lname>
</UserDetails>

请帮助。

2 个答案:

答案 0 :(得分:0)

你不能这样做,因为你会违反SOAP协议。有关类似问题,请考虑this个答案。

答案 1 :(得分:0)

我正在使用以下方法来完成上述要求。 这是部分SOAP和部分REST。 :P

php://input

php:// input是一个只读流,允许您从请求正文中读取原始数据。

server.php看起来像这样。

$HTTP_METHOD = $this->input->server('REQUEST_METHOD');

if($HTTP_METHOD!='POST'){
    echo "Invalid http method";
    die;
}

$data = fopen('php://input','rb');
$Headers = getallheaders();
$CLength  = $Headers['Content-Length'];
$content = fread($data,$CLength);

//Here We can Parse Request XML and get required SOAP header and Soap Body out of it

/*
//Here We can write our business logic


*/


echo $resonse;   //In this we can built custom xml and simple echo

如果你有比这个善意更好的建议。

谢谢