【发布时间】:2015-05-22 12:24:42
【问题描述】:
我有以下 - 当前托管 - 我试图从 PHP 调用的 .NET 中创建的 SOAP 服务:
POST /ExampleService/ExampleService.asmx HTTP/1.1
Host: dev.examplesite.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://localhost:51713/ExampleService.asmx/RegisterPerson"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<UserCredentials xmlns="http://localhost:51713/ExampleService.asmx">
<UserID>string</UserID>
<AuthKey>string</AuthKey>
</UserCredentials>
</soap:Header>
<soap:Body>
<RegisterPerson xmlns="http://localhost:51713/ExampleService.asmx">
<requestItem>
<RequestResult>string</RequestResult>
<Firstname>string</Firstname>
<Lastname>string</Lastname>
</requestItem>
</RegisterPerson>
</soap:Body>
</soap:Envelope>
我正在尝试使用以下 PHP 代码调用它:
<?php
$ns = "http://dev.examplesite.com/ExampleService/ExampleService.asmx";
$wsdl_url = "http://dev.examplesite.com/ExampleService/ExampleService.asmx?wsdl";
$client = new SOAPClient($wsdl_url);
$header = new SoapHeader(
$ns,
'UserCredentials',
array(
'UserID' => "1",
'AuthKey' => "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX"
)
);
$client->__setSoapHeaders($header);
$params = array(
'Firstname' => 'John',
'Lastname' => 'Doe'
);
$client->__soapCall('RegisterPerson',$params);
?>
然而,这会导致以下错误:
Fatal error: Uncaught SoapFault exception: [soap:MustUnderstand] Missing required header 'UserCredentials'. in /home/devops1/public_html/asmxtest/register.php:43 Stack trace: #0 /home/devops1/public_html/asmxtest/register.php(43): SoapClient->__soapCall('RegisterPerso...', Array) #1 {main} thrown in /home/devops1/public_html/asmxtest/register.php on line 43
我尝试了其他一些方法,但都没有成功。让我担心的一件事是,我们正在通过有线到达这个已经托管在测试服务器上的 Web 服务,并且 localhost:51713 正在响铃警钟。是否应该将其更改为完全限定的域名,例如dev.examplesite.com?
【问题讨论】:
-
我最好的猜测是手动设置用户名/密码的标题不是正确的方法,并且它被覆盖了..但这只是一个很难的猜测..虽然可以很容易地用 curl 完成这个 1 请求
-
感谢hanshenrik 的回复。请详细说明
-
可能的代理/防火墙问题?
标签: php asmx soap-client