david 的个人资料David Yardy PE, MCSD.NET...照片日志列表 工具 帮助

日志


11月28日

Web Service Authentication with NTLM

So recently had an issue with a web application calling a web service within another web application on the same server.

I created the proxy with Visual Studio and set the web service credentials via wsProxy = System.Net.CredentialCache.DefaultCredentials

This would not work.

I modified the code slightly so that I passed in my windows domain username and password (which is fine if calling from windows application) to the web service. 

Dim cr As New System.Net.NetworkCredential(wsusername,wspassword, wsdomain)
wsProxy.Credentials = cr

This did work.

So, the difference being that for ASP.NET programs, the default credentials are the user credentials of the identity for the ASP.NET worker process, or the user who is being impersonated.   

DefaultCredentials represents the ASPNET user account (or NetworkService user account for applications run on Microsoft Internet Information Services [IIS] 6.0) because no impersonation is set to the caller.

End result was wrapping the web service call in impersonation wrapper to use the current web user (not the NetworkService account).

Dim impersonationContext As System.Security.Principal.WindowsImpersonationContext
Dim currentWindowsIdentity As System.Security.Principal.WindowsIdentity

currentWindowsIdentity = CType(System.Web.HttpContext.Current.User.Identity, System.Security.Principal.WindowsIdentity)

impersonationContext = currentWindowsIdentity.Impersonate()

wsProxy.Credentials = CredentialCache.DefaultCredentials

Dim data as string = wsProxy.GetData("pass something in")  'call web service

impersonationContext.Undo()
impersonationContext = Nothing

This worked nicely and helped me avoid hard coding in a windows service account somewhere in the application.

11月21日

Read Only Properties (Web Service / WCF / Serialization)

I ran into this issue with an existing object that is setup through 'adapter' pattern.  The problem is that a read-only property cannot be serialized in the same way that a read/write property can be.

So, what do you do with all the read-only properties?

Choices...

  • make the read-only properties read-write
    • while putting throw exception in the setter
    • put  code that is not used in the setter portion
  • define the get accessor as <OperationsContract()> _

   [ServiceContract]
    public interface ITest
    {
        bool EnablePasswordReset {
            [OperationContract] get;
        }
        .........
    }

Notice that if you generate the proxy for this service you might see the property transformed into a method (called get_EnablePasswordReset). 

Know of other options fill me in.

WCF Wows and Woes!

I am able to create a WCF Service and expose via basicHttpBinding (while hosted on IIS 6).  Things are good however; the problem I am currently having is related to the proxy that gets generated from vs.net 2005. 

If I try to transfer a dataset in addition to my custom class the proxy generated has duplicate class type definitions.  See image below for a view of both definitions.

The Error List has the following error.

Error    300    'agreementField' is already declared as 'Private Dim AgreementField As String' in this class.    C:\Inetpub\wwwroot\SignatureAuth\374\Ver1.0\Test374\Service References\WF374WCF.vb    1431    17    Test374

In my interface if I comment out the following lines things work ok.  So, at this point it seems that if I try to expose a custom object type in addition to a dataset I get the error above.

<OperationContract()> _
Function WFData1(ByVal wf374id As Integer) As DataSet

clip_image002

If anyone has seen this issue and knows the solution please let me know.

11月19日

Enthusiastic Telerik User

Telerik continues their impressive technical support with 21 new online tutorial videos for their Asp.Net suite of tools.  The videos demonstrate their consistent impressive technical support for the end user.  One of the most important features for purchased components...support!

The online videos are categorized by product and control feature allowing for quick navigation to technical implementation information.

New videos found here (http://www.telerik.com/support/videos.aspx)

telerik

11月9日

Visual Studio 2008 - in time for Christmas 2007!

Microsoft Commits to November Release Date for Visual Studio 2008 and the .NET Framework 3.5 see notes here

11月3日

LCD Monitors

Ever notice in BestBuy or Circuit City that some LCD monitors just don't look as good as others?  I cam across this blog entry here and a related lcd buying guide as a resource.  If you are in the market for a new monitor check these out.

Additional Resources

 

Check them out.