使用 SoapHeader() 调用将 .NET 语法转换为 PHP

发布于 2024-07-27 04:04:47 字数 216 浏览 6 评论 0原文

我需要使用 SoapHeader() 调用将此 .NET 语法转换为 PHP。

esb.RequestServerVersionValue = new RequestServerVersion(); esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2007_SP1;

多谢! :)

I need to convert this .NET syntax into PHP using SoapHeader() call.

esb.RequestServerVersionValue = new RequestServerVersion();
esb.RequestServerVersionValue.Version = ExchangeVersionType.Exchange2007_SP1;

Thanks a lot! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柳若烟 2024-08-03 04:04:48
$soapHeader = new SoapHeader(
                     'http://schemas.microsoft.com/exchange/services/2006/types',
                     'RequestServerVersion Version="Exchange2007_SP1"'
                     );

$client->__setSoapHeaders($soapHeader);

这基本上就是真正需要设置的全部内容。 我对命名空间设置感到困惑。 奇怪的是,在使用公用文件夹时需要 RequestServerVersion 标头,但在 Exchange 2007 中使用邮箱项目时似乎不需要。

此链接特别有用:http://www.zimbra.com/forums/developers/5532-php -soap-vs-zimbra.html 因为它向我展示了如何启用调试并非常清楚每个属性的作用。

此 Google 搜索结果显示了生成此功能所需的有效 XML“t:RequestServerVersion”

$soapHeader = new SoapHeader(
                     'http://schemas.microsoft.com/exchange/services/2006/types',
                     'RequestServerVersion Version="Exchange2007_SP1"'
                     );

$client->__setSoapHeaders($soapHeader);

This is basically all that really needed to be set. I got confused with namespace settings. Curiously, RequestServerVersion header is required when working with public folders, but does not appear to be required when working with mailbox items in Exchange 2007.

This link was particularly helpful: http://www.zimbra.com/forums/developers/5532-php-soap-vs-zimbra.html as it showed me how to enable debugging and made it very clear what each attribute did.

This Google search result shows valid XML necessary to generate for this to work "t:RequestServerVersion"

╄→承喏 2024-08-03 04:04:48

我个人在使用 SoapHeader 类时从未设法按照我想要的方式获取标头。 为了更加灵活,您也许应该采用自定义 SoapClient 类考虑在内。 正如我在另一个问题中回答的那样因此,您可以在覆盖 SoapClient 时根据需要构造 SOAP 消息: :__doRequest()。 这样您就可以随意插入 XML 片段。

class My_SoapClient extends SoapClient
{
    protected function __doRequest($request, $location, $action, $version) 
    {
        /*
         * $request is a XML string representation of the SOAP request
         * that can e.g. be loaded into a DomDocument to make it modifiable.
         */
        $domRequest = new DOMDocument();
        $domRequest->loadXML($request);

        // modify XML using the DOM API, e.g. get the <s:Header>-tag 
        // and add your custom headers
        $xp = new DOMXPath($domRequest);
        $xp->registerNamespace('s', 'http://www.w3.org/2003/05/soap-envelope');
        $headers = $xp->query('/s:Envelope/s:Header');
        if ($headers->length == 0) {
            $envelope = $xp->query('/s:Envelope')->item(0);
            $header = $domRequest->createElementNS('http://www.w3.org/2003/05/soap-envelope', 's:Header');
            $envelope->appendChild($header);
        } else {
            $header = $headers->item(0);
        }

        // now add your custom header
        $requestServerVersion = $domRequest->createElementNS('T_NAMSPACE', 't:RequestServerVersion');
        $requestServerVersion->setAttribute('Version', 'Exchange2007_SP1');
        
        $header->appendChild($requestServerVersion);

        $request = $domRequest->saveXML();
        return parent::__doRequest($request, $location, $action, $version);
    }
}

T_NAMSPACE 必须更改为前缀 t 的正确命名空间。

I personally never managed to get the headers the way I wanted them when using the SoapHeader class. To be more flexible you should perhaps take a custom SoapClient class into consideration. As I answered in another question on SO you can structure the SOAP message to your needs when overriding SoapClient::__doRequest(). That way you can insert XML fragments at will.

class My_SoapClient extends SoapClient
{
    protected function __doRequest($request, $location, $action, $version) 
    {
        /*
         * $request is a XML string representation of the SOAP request
         * that can e.g. be loaded into a DomDocument to make it modifiable.
         */
        $domRequest = new DOMDocument();
        $domRequest->loadXML($request);

        // modify XML using the DOM API, e.g. get the <s:Header>-tag 
        // and add your custom headers
        $xp = new DOMXPath($domRequest);
        $xp->registerNamespace('s', 'http://www.w3.org/2003/05/soap-envelope');
        $headers = $xp->query('/s:Envelope/s:Header');
        if ($headers->length == 0) {
            $envelope = $xp->query('/s:Envelope')->item(0);
            $header = $domRequest->createElementNS('http://www.w3.org/2003/05/soap-envelope', 's:Header');
            $envelope->appendChild($header);
        } else {
            $header = $headers->item(0);
        }

        // now add your custom header
        $requestServerVersion = $domRequest->createElementNS('T_NAMSPACE', 't:RequestServerVersion');
        $requestServerVersion->setAttribute('Version', 'Exchange2007_SP1');
        
        $header->appendChild($requestServerVersion);

        $request = $domRequest->saveXML();
        return parent::__doRequest($request, $location, $action, $version);
    }
}

T_NAMSPACE must be changed to the correct namespace of prefix t.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文