Creating and accessing XML Web services

Posted on

These questions are based on Cert-70-554VB – MSCert: UPGRADE – MCSD Microsoft .NET Skills to MCPD Enterprise Application Developer Using the Microsoft .NET Framework: Part 2 – Section 1 Microsoft Developer Self-Test Software Practice Test.

 

Objective: Creating and accessing XML Web services
SubObjective: Create and configure an XML Web service method

 

Single Answer, Multiple Choice

 

You are an enterprise application developer at ESoft Corp. You are creating an XML Web service named ClaimService for an insurance organization. The Web service connects to multiple data sources, including a DB2 and SQL Server 2005 database, to retrieve and process customer claim data. The ClaimService Web service is defined as:

 

Public Class ClaimService
Inherits WebService
<WebMethod()> _
Public Function ProcessClaim(ByVal ClaimID As String) As Integer
‘Implementation code
End Function
End Class

 

The ProcessClaim method must authenticate with each database using the network credentials of the client application. The client application requires all users to log into the Windows domain before processing or accessing claim data. Which code should you use to invoke the ProcessClaim method?

 

 

  1. Dim proxy As New ClaimService
    Dim nc As New System.Net.NetworkCredential(“CurrentUser”,”Pa$$w0rd”)
    Dim cc As New System.Net.CredentialCache()
    cc.Add(New Uri(proxy.Url), “Basic”, nc)
    proxy.Credentials = cc
    proxy.ProcessClaim(“1001″)

 

 

  1. Dim proxy As New ClaimService
    proxy.Credentials = System.Net.CredentialCache.DefaultCredentials
    proxy.ProcessClaim(“1001″)

 

 

  1. Dim proxy As New ClaimService
    Dim cc As New System.Net.CredentialCache()
    proxy.Credentials = cc.DefaultNetworkCredentials
    proxy.ProcessClaim(“1001″)

 

 

  1. Dim proxy As New ClaimService
    proxy.Credentials =

    1. System.Net.CredentialCache.DefaultNetworkCredentials

    proxy.ProcessClaim(“1001″)

 

Answer:

 

 

  1. Dim proxy As New ClaimService
    proxy.Credentials =

    1. System.Net.CredentialCache.DefaultNetworkCredentials

    proxy.ProcessClaim(“1001″)

 

Tutorial:
You should use the following code to invoke the ProcessClaim method with the current client login credentials:

 

Dim proxy As New ClaimService
proxy.Credentials =
System.Net.CredentialCache.DefaultNetworkCredentials
proxy.ProcessClaim(“1001″)

 

This code is correct because it sets the Credentials property of the Web proxy to the network credentials of the current security context and then calls the Web method. This code instantiates a ClaimService Web proxy and sets the Credentials property to the DefaultNetworkCredentials property of the CredentialCache class. When the ProcessClaim method is invoked, the domain credentials will be sent to the ClaimService Web service for authentication with the required databases.

 

The CredentialCache class is used to store credentials for multiple resources. Whenever such a resource is requested, the credentials for the resource are retrieved from the CredentialCache class for authentication. This class has two properties:
DefaultCredentials: Retrieves the local system credentials of the current security context. The system credentials refer to the account(s) on the local machine.
DefaultNetworkCredentials: Retrieves the network credentials of the current security context. The network credentials refer to the local account(s) impersonated across the network or Windows domain.

 

You should not use the following code to invoke the ProcessClaim method with the current client login credentials:

 

Dim proxy As New ClaimService
Dim nc As New System.Net.NetworkCredential(“CurrentUser”,”Pa$$w0rd”)
Dim cc As New System.Net.CredentialCache()
cc.Add(New Uri(proxy.Url), “Basic”, nc)
proxy.Credentials = cc
proxy.ProcessClaim(“1001″)

 

This code does not specify the current network credentials of the client application because it codes new network credentials. It instantiates a new NetworkCredential object with the username and password as “CurrentUser” and “Pa$$w0rd,” respectively. The code then instantiates a CredentialCache object and adds the NetworkCredential object. The Add method takes three parameters: the uniform resource identifier (URI) of the Web service, the authentication protocol (basic, digest or integrated) as a string, and NetworkCredential instance. Then, the Credentials property of the Web proxy is set to CredentialCache object and the ProcessClaim method is invoked. This will send new network credentials to the ClaimService Web service. In this scenario, you should use the DefaultNetworkCredentials property to specify the network credentials of the current client login.

 

You should not use the code that specifies the DefaultCredentials property because this does not represent the network credentials for the current client login. The DefaultCredentials property indicates the system credentials on the local machine, not the credentials across the network. In this scenario, you should use the DefaultNetworkCredentials property to specify the network credentials of the current client login.

 

You should not use the code that instantiates a CredentialCache object and specifies the DefaultNetworkCredentials property because this property is a class member. Thus, you do not need to and should not instantiate a CredentialCache object to specify the DefaultNetworkCredentials property.

 

Reference:
MSDN2 Library, Search, “.NET Development,” “.Net Framework SDK,” “Class Library Reference,” “System.Net,” “CredentialCache Class.”

 

MSDN2 Library, Search, “.NET Development,” “.Net Framework SDK,” “Class Library Reference,” “System.Net,” “NetworkCredential Class.”

 

MSDN2 Library, Search, “.NET Development,” “.Net Framework SDK,” “Class Library Reference,” “System.Net,” “CredentialCache Class,” “DefaultNetworkCredentials Proper

Like what you see? Share it.Share on Google+Share on LinkedInShare on FacebookShare on RedditTweet about this on TwitterEmail this to someone
cmadmin

ABOUT THE AUTHOR

Posted in Archive|

Comment: