2016-07-17 6 views
0

私が何をしても同じエラーが発生します。エラーは「認証ヘッダーがありません!認証できません!」です。Php Soap .netサービス認証ヘッダーがありません。認証することができません

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="xxxx" xmlns:ns2="xxxx" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <SOAP-ENV:Header> 
     <ns2:ApiAuthentication> 
      <LoginName>xxxx</LoginName> 
      <Password>xxxx</Password> 
      <Company>xxx</Company> 
     </ns2:ApiAuthentication> 
    </SOAP-ENV:Header> 
    <SOAP-ENV:Body> 
     <ns1:GetCustomersRequest> 
      <ns1:CustomerID>123456</ns1:CustomerID> 
      <ns1:LoginName xsi:nil="true" /> 
      <ns1:FirstName xsi:nil="true" /> 
      <ns1:LastName xsi:nil="true" /> 
      <ns1:Company xsi:nil="true" /> 
      <ns1:Email xsi:nil="true" /> 
      <ns1:Phone xsi:nil="true" /> 
      <ns1:Phone2 xsi:nil="true" /> 
      <ns1:MobilePhone xsi:nil="true" /> 
      <ns1:Fax xsi:nil="true" /> 
      <ns1:MainAddress1 xsi:nil="true" /> 
      <ns1:MainAddress2 xsi:nil="true" /> 
      <ns1:MainAddress3 xsi:nil="true" /> 
      <ns1:MainCity xsi:nil="true" /> 
      <ns1:MainState xsi:nil="true" /> 
      <ns1:MainZip xsi:nil="true" /> 
      <ns1:MainCountry xsi:nil="true" /> 
      <ns1:TaxID xsi:nil="true" /> 
      <ns1:EnrollerID xsi:nil="true" /> 
      <ns1:SponsorID xsi:nil="true" /> 
      <ns1:Field1 xsi:nil="true" /> 
      <ns1:Field2 xsi:nil="true" /> 
      <ns1:Field3 xsi:nil="true" /> 
      <ns1:Field4 xsi:nil="true" /> 
      <ns1:Field5 xsi:nil="true" /> 
      <ns1:Field6 xsi:nil="true" /> 
      <ns1:Field7 xsi:nil="true" /> 
      <ns1:Field8 xsi:nil="true" /> 
      <ns1:Field9 xsi:nil="true" /> 
      <ns1:Field10 xsi:nil="true" /> 
      <ns1:Field11 xsi:nil="true" /> 
      <ns1:Field12 xsi:nil="true" /> 
      <ns1:Field13 xsi:nil="true" /> 
      <ns1:Field14 xsi:nil="true" /> 
      <ns1:Field15 xsi:nil="true" /> 
      <ns1:CreatedDateStart xsi:nil="true" /> 
      <ns1:CreatedDateEnd xsi:nil="true" /> 
      <ns1:GreaterThanCustomerID xsi:nil="true" /> 
      <ns1:GreaterThanModifiedDate xsi:nil="true" /> 
      <ns1:BatchSize xsi:nil="true" /> 
     </ns1:GetCustomersRequest> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

And here is the response: 

    <?xml version="1.0" encoding="UTF-8"?> 
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soap:Body> 
     <soap:Fault> 
      <faultcode>soap:Server</faultcode> 
      <faultstring>Authentication header missing! Unable to Authenticate!</faultstring> 
      <detail /> 
     </soap:Fault> 
    </soap:Body> 
</soap:Envelope> 

そして、私のPHPコード:ここで

が私の要求から生成されたXMLである

$client = new SoapClient("http://mywebservice.asmx?wsdl", 
array(
    "trace"  => 1, 
    "exceptions" => 0, 
    "cache_wsdl" => 0) 
); 

$namespace = 'http://mynamespace.com'; 

$creds = new stdClass(); 
$creds->LoginName = "xxxx"; 
$creds->Password = "xxxx"; 
$creds->Company = "xxxx"; 

$headers[] = new SoapHeader($namespace, 'ApiAuthentication', $creds, false); 

$client->__setSoapHeaders($headers); 

$response = $client->__soapCall("GetCustomers", array("CustomerID" => "123456")); 
var_dump($response); 

私は自分のコードの上に数回してきたし、何かを見つけることができません。私は資格を設定し、石鹸のクライアントと石鹸のヘッダーなどを設定するコードの複数のバリエーションを試してみました。

毎回同じ応答が "認証ヘッダーがありません!

確認事項はありません。私は過去数年間dot.netをやっていて、ちょうどPHPに戻っています。

ありがとうございます。

答えて

0

ヘッダーの代わりにクッキーを使用します。あなたがヘッダーでそれをやっているのを見つけたら、教えてください。

PHP

$client = new SoapClient('http://somesite/someservice.asmx?wsdl'); 
$client->__setCookie("LoginName", "myname"); 
$client->__setCookie("Password", "secret"); 
$client->__setCookie("Company", "999999999"); 

ASP.NET

string strLoginName = HttpContext.Current.Request.Cookies.Get("LoginName").Value; 
string strPassword = HttpContext.Current.Request.Cookies.Get("Password").Value; 
string strCompany = HttpContext.Current.Request.Cookies.Get("Company").Value; 
+0

これはヘッダが送信されません理由について、ユーザーの主な問題に対処しません。このような状況でOPがクッキーの認証ヘッダーを捨てなければならない理由はここにありますか?そこには多くのトレードオフがあります。また、上記のASP.NETコードはこの質問とは関係ありません。 –

関連する問題