PHP SoapServer格式 [英] PHP SoapServer formatting

查看:104
本文介绍了PHP SoapServer格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是SOAP的新手,正在尝试使用PHP的SoapServer类格式化SOAP响应.

I am new to SOAP and trying to format a SOAP response using PHP's SoapServer class.

知道这是针对 EWS推送订阅回调服务,并且我正在使用 php-ews 库.我已经成功订阅了EWS推送订阅,但是在格式化EWS期望从我的回调服务获得的答复时遇到了麻烦.

It might be useful to know that this is for an EWS Push Subscription callback service and that I am using the php-ews library. I have managed to subscribe to the EWS Push Subscription but am having trouble formatting the reply which EWS is expecting from my callback service.

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

I need the following SOAP response returned by my PHP SOAP service:

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

相反,我得到以下输出:

Instead I am getting the following output:

<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服务代码:

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调用如下:

The SOAP call to my service is as follows:

<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 SoapServer类更改SOAP响应的格式?我是否需要添加WSDL或将类映射传递给SoapServer构造函数?

So I suppose my question is how do I to change the formatting of the SOAP response, using the PHP SoapServer class? Do I need to add a WSDL or pass a classmap to the SoapServer constructor?

如果没有办法使用SoapServer类来执行此操作,除了创建字符串缓冲区并将其手动传递回去之外,还有其他方法可以执行此操作吗?

If there is no way to do this using the SoapServer class, is there any other way to do this other than creating a string buffer and passing that back manually?

任何帮助将不胜感激.

推荐答案

我弄清楚了这一点,并在此问题的更一般性问题上发布了解决方案

I figured this out and posted the solution on a more generic question of this problem here

为完整起见,我也在此处提供了答案...

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

It would seem that I was close but needed to include the NotificationService.wsdl when instantiating the SoapServer class. The WSDL then allows that SoapServer class to format the response accordingly.

$server = new SoapServer( PHPEWS_PATH.'/wsdl/NotificationService.wsdl', array(

WSDL未包含在php-ews库下载中,但已包含在Exchange Server安装中.如果像我一样,您无权访问Exchange Server安装,则可以找到文件

The WSDL was not included in the php-ews library download, however it is included with the Exchange Server installation. If like me you don't have access to the Exchange Server installation you can find the file here. I also had to add the following to the end of the WSDL because I was storing the WSDLs locally and not using autodiscovery:

<wsdl:service name="NotificationServices">
    <wsdl:port name="NotificationServicePort" binding="tns:NotificationServiceBinding">
        <soap:address location="" />
    </wsdl:port>
</wsdl:service>

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

So the full working PHP code is as follows:

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

哪个给出以下输出:

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

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

Hope that helps someone else because that took me a while to figure out!

这篇关于PHP SoapServer格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆