2011-07-11 5 views
4

私はPHPサイトから安全なWCF Webサービスを浪費しています。私のPHPに関する知識は限られていますが、私はWeb上でさまざまな例を見つけましたが、まだそれらを動作させることに成功しませんでした。PHPページでカスタムユーザー名検証を使用するWCF Webサービスを使用するにはどうすればよいですか?

私は、このWebServiceも使用するSilverlightアプリケーションを持っていますが、正常に動作します。しかし、私はPHPサイトを実行すると、私はこのエラーが表示されます:

MessageSecurityException:セキュリティプロセッサは、メッセージ内のセキュリティヘッダーを見つけることができませんでした。これは、メッセージが保護されていない障害であるか、または通信相手間にバインディングの不一致があるためです。これは、サービスがセキュリティのために構成されており、クライアントがセキュリティを使用していない場合に発生します。

また、customBindingをbasicHttpBindingに変更しようとしました。私がそれをすると、カスタムユーザー名バリデーターはもはや呼び出されません。しかし、basicHttpBindingを使用し、私のWCFサービスで資格情報の検証を削除することは "機能します"(それはセキュリティ保護されていないという事実以外にも)。したがって、問題はセキュリティメッセージに関連しているようです。

誰かが私にこのPHPページを動作させるのに役立つ作業例やチュートリアルを教えてもらえますか?ここで

は私のPHPコードです:

$options = array( 
      'soap_version' => SOAP_1_1, 
      'exceptions' => true, 
      'trace'   => 1, 
      'cache_wsdl' => WSDL_CACHE_NONE, 
      'Username'  => 'MyUserName', 
      'password'  => 'MyPassword'); 

$client = new SoapClient('https://UrlToService/Service.svc?wsdl', $options); 

try 
{ 
    $phpresponse = $client->Get(); 

    print $phpresponse->GetResult->Version; 
    echo "</b><BR/><BR/>"; 
} 
catch(Exception $e) 
{ 
    echo "<h2>Exception Error!</h2></b>"; 
    echo $e->getMessage(); 
    echo "<BR/><BR/>"; 
} 

WCFの設定

<behavior name="sslBehavior"> 
    <serviceMetadata httpsGetEnabled="true" /> 
    <serviceDebug includeExceptionDetailInFaults="true" /> 
    <serviceCredentials> 
     <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyNamespace.ServiceUserNameValidator, MyNamespace" /> 
    </serviceCredentials> 
    <serviceSecurityAudit 
    auditLogLocation="Application" 
    serviceAuthorizationAuditLevel="Failure" 
    messageAuthenticationAuditLevel="Failure" 
    suppressAuditFailure="true" /> 
</behavior> 

<customBinding> 
    <binding name="sslCustomBinding"> 
     <security authenticationMode="UserNameOverTransport" includeTimestamp="true" allowInsecureTransport="true"> 
     <localServiceSettings maxClockSkew="00:10:00" /> 
     <localClientSettings maxClockSkew="00:10:00" /> 
     <secureConversationBootstrap /> 
     </security> 
     <textMessageEncoding messageVersion="Soap11" /> 
     <httpsTransport /> 
    </binding> 
    </customBinding> 

<service behaviorConfiguration="sslBehavior" name="MyNamespace.Services.Service"> 
    <endpoint address="" binding="customBinding" 
       bindingConfiguration="sslCustomBinding" contract="MyNamespace.ServiceContracts.IService" /> 
    <host> 
     <baseAddresses> 
     <add baseAddress="https://UrlToService/Services/" /> 
     </baseAddresses> 
    </host> 
    </service> 

答えて

8

私はこの問題を解決しました。私は、WS-Security標準に準拠させるために、PHPで "SoapHeader"クラスを拡張しなければなりませんでした。ここで

は、ソリューションです:

PHPヘッダークラ​​ス

class WsseAuthHeader extends SoapHeader 
{ 
    private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd'; 
    function __construct($user, $pass, $ns = null) 
    {  
     if ($ns) 
     {   
      $this->wss_ns = $ns;  
     }  

     $auth = new stdClass();  

     $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);  
     $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);  
     $username_token = new stdClass();  
     $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);  
     $security_sv = new SoapVar(  
           new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns),   
           SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);  

     parent::__construct($this->wss_ns, 'Security', $security_sv, true); 
    } 
} 

PHPクライアントコール

$options = array( 
      'soap_version' => SOAP_1_1, 
      'exceptions'  => true, 
      'trace'   => 1, 
      'wdsl_local_copy' => true 
      ); 


$username = "MyUser"; 
$password = "MyPassword"; 

$wsse_header = new WsseAuthHeader($username, $password);  

$client = new SoapClient('https://UrlToService/Service.svc?wsdl', $options); 
$client->__setSoapHeaders(array($wsse_header)); 

try 
{ 
    $phpresponse = $client->Get(); 

    print $phpresponse->GetResult->Version; 
    echo "</b><BR/><BR/>"; 
} 
catch(Exception $e) 
{ 
    echo "<h2>Exception Error!</h2></b>"; 
    echo $e->getMessage(); 
} 

、それは他の誰かに役立ちます願っています!クリスへ

ありがとう:Connecting to WS-Security protected Web Service with PHP

+0

YEEEEEEES ITが私を助けました! –

+0

これも私を助けました!素晴らしい解決策! – Trond

0

SOAPは、認証と少しおかしい(またはすることができます)、私はからhttp://www.php.net/manual/en/soapclient.soapclient.php#101503参照してくださいコメントからメソッドを使用しています、faebuのfuebuで2010年12月21日2時58分ちょうどこれを数回行うために...それは助けるかもしれない

本質的に私たち認証証明書を渡すためのCURL ...それはあなたのために働くかもしれません!

+0

私はちょうどそれを試してみましたが、残念ながら、それは動作しません。私はXMLが作成されて参照してください、私はまだ同じ例外が表示されます。 – PiercingDegree

関連する問題