首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP SoapServer格式

PHP SoapServer格式
EN

Stack Overflow用户
提问于 2014-08-19 20:15:52
回答 1查看 1K关注 0票数 0

我对SOAP很陌生,并且尝试使用PHP的SoapServer类格式化SOAP响应。

如果知道这是用于推送订阅回调服务的,并且我正在使用php-ews库,这可能是有用的。我已经成功地订阅了EWS推送订阅,但是在格式化EWS期望从我的回调服务中得到的回复时遇到了问题。

我需要PHP SOAP服务返回的以下SOAP响应:

代码语言:javascript
复制
<s:Envelope xmlns:s= "http://schemas.xmlsoap.org/soap/envelope/">
    <s:Body>
        <SendNotificationResult xmlns="http://schemas.microsoft.com/exchange/services/2006/messages">
            <SubscriptionStatus>OK</SubscriptionStatus>
        </SendNotificationResult>
    </s:Body>
</s:Envelope>

相反,我得到了以下输出:

代码语言:javascript
复制
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://localhost/ioc/ebooking_v4/services/ews/notification.php" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
    <SOAP-ENV:Body>
        <ns1:SendNotificationResponse>
            <return xsi:type="SOAP-ENC:Struct">
                <SubscriptionStatus xsi:type="xsd:string">OK</SubscriptionStatus>
            </return>
        </ns1:SendNotificationResponse>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

我的PHP服务代码:

代码语言:javascript
复制
class ewsService {
    public function SendNotification( $arg ) {
        $result = new EWSType_SendNotificationResultType();
        $result->SubscriptionStatus = 'OK';
        return $result;
    }
}

$server = new soapServer( null, array(
    'uri' => $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'],
));
$server->setObject( new ewsService() );
$server->handle();

对我的服务的SOAP调用如下:

代码语言:javascript
复制
<soap11:Envelope xmlns:soap11="http://schemas.xmlsoap.org/soap/envelope/">
    <soap11:Header>
        <t:RequestServerVersion xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages" Version="Exchange2010_SP2" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" />
    </soap11:Header>
    <soap11:Body>
        <m:SendNotification xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types" xmlns:m="http://schemas.microsoft.com/exchange/services/2006/messages">
            <m:ResponseMessages>
                <m:SendNotificationResponseMessage ResponseClass="Success">
                    <m:ResponseCode>NoError</m:ResponseCode>
                    <m:Notification>
                        <t:SubscriptionId>GQBjaGNpb2ExODEuY2lvLm9seW1waWMub3JnEAAAAFgvEpJcS3JDkpvHOMgnX60FhmhpPInRCA==</t:SubscriptionId>
                        <t:PreviousWatermark>AQAAAIiCiXu/q1ZPvYPyvRVVh5cajSoKAAAAAAA=</t:PreviousWatermark>
                        <t:MoreEvents>false</t:MoreEvents>
                        <t:StatusEvent>
                            <t:Watermark>AQAAAIiCiXu/q1ZPvYPyvRVVh5cajSoKAAAAAAA=</t:Watermark>
                        </t:StatusEvent>
                    </m:Notification>
                </m:SendNotificationResponseMessage>
            </m:ResponseMessages>
        </m:SendNotification>
    </soap11:Body>
</soap11:Envelope>

因此,我想我的问题是如何使用PHP类更改SOAP响应的格式?我需要添加WSDL还是将类映射传递给SoapServer构造函数?

如果无法使用SoapServer类执行此操作,那么除了创建字符串缓冲区并手动将其传回之外,还有其他方法吗?

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-21 09:06:14

我想出了这个问题,并在这个问题上发布了一个更通用的解决方案,这里

,为了完整,我在这里也给出了答案.

似乎我很接近,但是在实例化NotificationService.wsdl类时需要包含SoapServer。然后,WSDL允许该SoapServer类相应地格式化响应。

代码语言:javascript
复制
$server = new SoapServer( PHPEWS_PATH.'/wsdl/NotificationService.wsdl', array(

WSDL没有包含在php-ews库下载中,但是它包含在Exchange安装中。如果像我一样,您无法访问Exchange安装,则可以找到文件这里。我还必须在WSDL的末尾添加以下内容,因为我是在本地存储WSDL,而不是使用自动发现:

代码语言:javascript
复制
<wsdl:service name="NotificationServices">
    <wsdl:port name="NotificationServicePort" binding="tns:NotificationServiceBinding">
        <soap:address location="" />
    </wsdl:port>
</wsdl:service>

因此,完整的PHP代码如下:

代码语言:javascript
复制
class ewsService {
    public function SendNotification( $arg ) {
        $result = new EWSType_SendNotificationResultType();
        $result->SubscriptionStatus = 'OK';
        //$result->SubscriptionStatus = 'Unsubscribe';
        return $result;
  }
}

$server = new SoapServer( PHPEWS_PATH.'/wsdl/NotificationService.wsdl', array(
    'uri' => $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'],
));
$server->setObject( $service = new ewsService() );
$server->handle();

它提供了以下输出:

代码语言:javascript
复制
<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/exchange/services/2006/messages">
    <SOAP-ENV:Body>
        <ns1:SendNotificationResult>
            <ns1:SubscriptionStatus>OK</ns1:SubscriptionStatus>
        </ns1:SendNotificationResult>
    </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

希望这对其他人有帮助,因为我花了一段时间才弄清楚!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25392228

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档