正 文

SQL Server 本机 Web 服务的使用方案


www.7dspace.com  更新日期:2005-10-4 9:49:52  七度空间


正如您可以在上述讨论中看到的那样,存在两种级别的身份验证:

• 传输级别

• 消息级别

现在,让我们深入探讨这两个级别的身份验证是如何工作的。

所有请求总是在传输级别进行身份验证。因此,如果用户提交无效的 BASIC 身份验证凭据,则连接失败,并且发生 HTTP 401 访问被拒绝错误。如果用户成功地在传输级别进行身份验证,则我们具有两个选择。我们可以使用传输凭据或作为 SOAP 消息的一部分到来的凭据登录 SQL Server。所选的凭据是由 SOAP 消息中是否存在 SQL-Auth 凭据确定的。如果 SOAP 消息中存在凭据,则我们将试图使用 SQL-Auth 凭据登录 SQL Server 数据库。如果该方法失败,则我们向用户返回失败,并且我们不会后退到使用 BASIC 身份验证凭据。如果 SOAP 消息中不存在凭据,则我们将试图使用传输凭据登录 SQL Server。

包含 SQL 凭据的 SOAP 消息如下所示:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <soap:Header>
    <Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-
    200401-wss-wssecurity-secext-1.0.xsd" xmlns="http://docs.oasis-
open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <wsse:UsernameToken>
        <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">
             password
       </wsse:Password>
      </wsse:UsernameToken>
    </Security>
  </soap:Header>
 <soap:Body>
   <GetCustomerInfoxmlns="http://Adventure-Works/Customers/">
     <CustomerID>1</CustomerID>
     <OutputParam>Hello World</OutputParam>
   </GetCustomerInfo>
 </soap:Body>
</soap:Envelope>

在 SOAP 消息中指定无效的凭据会产生以下 SOAP 错误(该错误被返回给用户):

<?xml version="1.0" encoding="utf-8"?>
<SOAP-ENV:Envelope xml:space="preserve" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-
ENV="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:sql="http://schemas.microsoft.com/sqlserver/2004/SOAP"
xmlns:sqlsoaptypes="http://schemas.microsoft.com/sqlserver/2004/SOAP/types"
xmlns:sqlrowcount="http://schemas.microsoft.com/sqlserver/2004/SOAP/types/
SqlRowCount"
xmlns:sqlmessage="http://schemas.microsoft.com/sqlserver/2004/SOAP/types/
SqlMessage"
xmlns:sqlresultstream="http://schemas.microsoft.com/sqlserver/2004/SOAP/types/
SqlResultStream"
xmlns:sqltransaction="http://schemas.microsoft.com/sqlserver/2004/SOAP/types/
SqlTransaction"
xmlns:sqltypes="http://schemas.microsoft.com/sqlserver/2004/sqltypes">
 <SOAP-ENV:Body>
   <SOAP-ENV:Fault xmlns:sqlsoapfaultcode="http://schemas.microsoft.com/sqlserver/2004/SOAP/
SqlSoapFaultCode">
     <faultcode>SOAP-ENV:Client</faultcode>
     <faultstring>
        There was an error in the incoming SOAPrequest packet: 
        Client, LoginFailure, AccessDenied
     </faultstring>
     <faultactor>http://schemas.microsoft.com/sqlserver/2004/SOAP</faultactor>
     <detail xmlns:SOAP-1_2-ENV="http://www.w3.org/2003/05/soap-envelope">
       <SOAP-1_2-ENV:Code>
         <SOAP-1_2-ENV:Value>SOAP-1_2-ENV:Sender</SOAP-1_2-ENV:Value>
         <SOAP-1_2-ENV:Subcode>
           <SOAP-1_2-ENV:Value>sqlsoapfaultcode:LoginFailure</SOAP-1_2-ENV:Value>
           <SOAP-1_2-ENV:Subcode>
             <SOAP-1_2-ENV:Value>sqlsoapfaultcode:AccessDenied</SOAP-1_2-ENV:Value>
           </SOAP-1_2-ENV:Subcode>
         </SOAP-1_2-ENV:Subcode>
       </SOAP-1_2-ENV:Code>
       <SOAP-1_2-ENV:Reason>
         <SOAP-1_2-ENV:Text xml:lang="en-US">
           There was an error in the incoming SOAPrequest packet: 
           Sender, LoginFailure, AccessDenied
         </SOAP-1_2-ENV:Text>
       </SOAP-1_2-ENV:Reason>
       <SOAP-1_2-ENV:Node>https://srikr-800.redmond.corp.microsoft.com:443/sql/sql_auth</SOAP-1_2-ENV:Node>
       <SOAP-1_2-ENV:Role>
           http://schemas.microsoft.com/sqlserver/2004/SOAP
       </SOAP-1_2-ENV:Role>
       <SOAP-1_2-ENV:Detail />
     </detail>
   </SOAP-ENV:Fault>
 </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

该解决方案只利用 HTTP、SOAP、BASIC 身份验证和 SSL,这使它对于异类环境很理想。在下一部分中,我们将看到如何利用该解决方案来创建 Perl 脚本,以便直接连接到 SQL Server。

5页,页码:[1] [2] [3] [4] [5] 

上一篇:修改大型 XML 文件的有效方法
下一篇:针对不可访问 Web 页的文本选择
作者:Srik Raghavan  来源:MSDN ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐