2011-10-25 15 views
1

私はruby gem Savonを使って、propertyware(http://propertyware.com/apidocs/Getting-Started)が提供するWebサービスに接続しようとしています。私は正常にSoapUI経由でサービスに接続し、echoStringリクエストを実行しました。 Ruby経由で同じことをしようとすると、nullユーザ認証エラーが発生します。ここでRuby-Savon Webサービス認証

はここSOAPUIによって生成されたXMLが...

<soapenv:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:web="http://webservices" > 
    <soapenv:Header> 
     <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
     <wsse:UsernameToken wsu:Id="UsernameToken-1" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"> 
      <wsse:Username>user</wsse:Username> 
      <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pwd</wsse:Password> 
      <wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">R41mCRd+tY+xthhE/YISLQ==</wsse:Nonce> 
      <wsu:Created>2011-10-25T09:52:40.220Z</wsu:Created> 
     </wsse:UsernameToken> 
     </wsse:Security> 
    </soapenv:Header> 
    <soapenv:Body> 
     <web:echoString soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> 
     <arg xsi:type="xsd:string">?</arg> 
     </web:echoString> 
    </soapenv:Body> 
</soapenv:Envelope> 
だ...私はRubyで試してみたものだ

次のXMLを生成
require 'rubygems' 
require 'savon' 

client = Savon::Client.new do 
    wsdl.document = 'http://propertyware.com/pw/services/PWServices?wsdl' 
    wsse.credentials 'username', 'pwd' 
end 

response = client.request :web, :echo_string, :body => {:arg => "Hello world."} 

...

<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:web="http://propertyware.com/pw/services/PWServices" 
    xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" 
    xmlns:ins0="http://propertyware.com/pw/services/PWServices" 
    xmlns:ins1="http://criteria.soap.propertyware.com" 
    xmlns:ins2="urn:PWServices" 
    xmlns:ins3="http://soap.propertyware.com" 
    xmlns:ins4="http://xml.apache.org/xml-soap"> 
    <env:Header> 
     <wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"> 
      <wsse:UsernameToken xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" wsu:Id="UsernameToken-1"> 
       <wsse:Username>user</wsse:Username> 
       <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">pwd</wsse:Password> 
      </wsse:UsernameToken> 
     </wsse:Security> 
    </env:Header> 
    <env:Body> 
     <web:echoString> 
      <arg>Hello world.</arg> 
     </web:echoString> 
    </env:Body> 
</env:Envelope> 

明らかな違いの1つは、SoapUIにnonceキーとcreatedAtタイムスタンプが含まれていることです。私はサバンナをどのようにして認証を消化することなくそれをするのかはわかりません。 (と動作しないfwiw)。

私はウェブサービスの方法では本当のサボイではありません - どんな指針も高く評価されます。

も ​​- 私はサボン経由で接続しようとしたとき、ここでの応答です:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <soapenv:Body> 
     <soapenv:Fault> 
      <faultcode xmlns:ns1="http://xml.apache.org/axis/">ns1:Server.Unauthenticated</faultcode> 
      <faultstring>User 'null' not authenticated (unknown user)</faultstring> 
      <detail> 
       <ns2:hostname xmlns:ns2="http://xml.apache.org/axis/">rcpppwwwapt012.realpage.com</ns2:hostname> 
      </detail> 
     </soapenv:Fault> 
    </soapenv:Body> 
</soapenv:Envelope> 

TIA! ボブ

答えて

2

wsseのダイジェストをtrueに設定してみてください。これは、要求にナンスとcreatedAtを追加するサボンを指示します:

wsse.credentials 'username', 'pwd', :digest 

は私が最初のステップは、エラーに対処するだろうと信じてthis object for more info

+0

感謝を。残念ながら、私が質問で指摘したように、ダイジェストをtrueに設定するとパスワードが暗号化されてしまい、動作しません。 –

0

のコメントを参照してください。

<faultstring>User 'null' not authenticated (unknown user)</faultstring> 

あなたの資格情報がサービスに渡されていません。サボンバージョン2では

+0

Yeap。それはこの質問が尋ねていることです - なぜそうですか?彼らは私に送られてきたように見えますが、なぜサーバーがそれを認めていないのか分かりません。 –

2

次の必要があります。提案のための

client = Savon.client do 
    wsdl 'https://webservice/theservice.wsdl' 
    wsse_auth("user", "pass", :digest) 
end 
関連する問題