我有以下 - 当前托管的 - 在.NET中创建的SOAP服务,我试图从PHP调用:
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
?
答案 0 :(得分:0)
就像SoapClient一样简单,我从未取得过成功。在几乎所有情况下,我们都推出了自己的流程,这似乎总是更好。
示例:
public void printPairsOfNumbers(int[] a, int sum){
//O(n2)
for (int i = 0; i < a.length; i++) {
for (int j = i+1; j < a.length; j++) {
if(sum - a[i] == a[j]){
//match..
System.out.println(a[i]+","+a[j]);
}
}
}
//O(n) time and O(n) space
Set<Integer> cache = new HashSet<Integer>();
cache.add(a[0]);
for (int i = 1; i < a.length; i++) {
if(cache.contains(sum - a[i])){
//match//
System.out.println(a[i]+","+(sum-a[i]));
}else{
cache.add(a[i]);
}
}
}
我们之后不得不按摩数据,但它始终有效!