使用PHP使用.NETWeb服务

使用PHP使用.NETWeb服务,php,web-services,soap,soap-client,nusoap,Php,Web Services,Soap,Soap Client,Nusoap,这是我第一次使用web服务/SOAP…我一直在尝试使用PHP使用.Net web服务,但没有效果。我已经搜索并阅读了谷歌抛出的所有与此相关的页面,但我仍然迷路了 问题是我试图调用的SOAP服务有一个授权头,我无法找到一种方法来验证我的请求 我已经尝试过PHPSOAPClient和NuSoap,但是没有可用的示例代码。因此,任何帮助都将是巨大的 下面是SOAP1.1请求和响应示例 POST /OxiWalletService/Service.asmx HTTP/1.1 Host: 172.160.

这是我第一次使用web服务/SOAP…我一直在尝试使用PHP使用.Net web服务,但没有效果。我已经搜索并阅读了谷歌抛出的所有与此相关的页面,但我仍然迷路了

问题是我试图调用的SOAP服务有一个授权头,我无法找到一种方法来验证我的请求

我已经尝试过PHPSOAPClient和NuSoap,但是没有可用的示例代码。因此,任何帮助都将是巨大的

下面是SOAP1.1请求和响应示例

POST /OxiWalletService/Service.asmx HTTP/1.1
Host: 172.160.0.49
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/WS_GetData"

<?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>
  <AuthHeader xmlns="http://tempuri.org/">
    <UserName>string</UserName>
    <Password>string</Password>
  </AuthHeader>
</soap:Header>
<soap:Body>
  <WS_GetData xmlns="http://tempuri.org/">
     <xmlString>string</xmlString>
  </WS_GetData>
</soap:Body>
</soap:Envelope>
应该是

$result=$soap_client->__SoapCall('WS_GetData',array('parameters'=>$param));

现在就可以了。

我认为这应该可以做到:


还可以查看教程,这是第一次。尽管启用了SOAPClient,但我得到了一个未定义的错误变量:第14行C:\wamp\www\soap1.php中的soap\u客户端和致命错误:第14行C:\wamp\www\soap1.php中非对象上的成员函数u\u setSoapHeaders()调用。实际上,您需要soap客户端实例,我的代码是局部的。在没有真实数据的情况下发布您的代码,我们将尝试查看您做错了什么。对我来说,WSDL甚至没有从url加载。非常感谢您的帮助。我找到了答案,并在上面发布了解决方案。非常感谢。先生,你刚刚救了我的周末。但愿我能给你买杯啤酒。
<?php 

$soap_client = new SoapClient("http://172.160.0.49/OxiWalletService/Service.asmx?WSDL");

$Uid='oxigen';
$Pwd='oxigen';
$ns = "http://tempuri.org/";

//Body of the Soap Header.
$headerbody = array('UserName' => $Uid,
                    'Password' => $Pwd
                   );
//Create Soap Header.       
$header = new SOAPHeader($ns, 'AuthHeader', $headerbody);       

//set the Headers of Soap Client.
$soap_client->__setSoapHeaders($header);
$par="<Wallet><SPName>AuthenticateMerchantWebVending</SPName><Parameters>&lt;Parameter&gt;&lt;Name&gt;@Account&lt;/Name&gt;&lt;Size&gt;50&lt;/Size&gt;&lt;Value&gt;1135600016&lt;/Value&gt;&lt;Type&gt;varchar&lt;/Type&gt;&lt;/Parameter&gt;&lt;Parameter&gt;&lt;Name&gt;@Password&lt;/Name&gt;&lt;Size&gt;20&lt;/Size&gt;&lt;Value&gt;0OgknrdonyM=&lt;/Value&gt;&lt;Type&gt;varchar&lt;/Type&gt;&lt;/Parameter&gt;</Parameters><ParameterCount>2</ParameterCount><DataBase>1</DataBase></Wallet>";
$param=array('xmlString'=>$par);

$result=$soap_client->__SoapCall('WS_GetData',$param);

print_r ($result);

?>
$result=$soap_client->__SoapCall('WS_GetData',$param);
$result=$soap_client->__SoapCall('WS_GetData',array('parameters'=>$param));
$ns = "http://tempuri.org/"

//Body of the Soap Header.
$headerbody = array('UserName' => $yourUsername,
                    'Password' => $yourPassword,
              );

//Create Soap Header.       
$header = new SOAPHeader($ns, 'AuthHeader', $headerbody);       

//set the Headers of Soap Client.
$soap_client->__setSoapHeaders($header);