Wcf issues - IIS and VS internal web server

Wcf issues - IIS and VS internal web server

Old forum URL: forums.lhotka.net/forums/t/4108.aspx


shaih posted on Thursday, January 03, 2008

Hi,

I have two problems (I think they might be connected)

I have an application a little similar to the project tracker example. I have built a Wcf channel, Wcf Service and Wcf client. I am trying to run the client to get information from the server (similar to the GetProjects example.

The first problem I have is getting a hard time to work with the Wcf service to host on IIS. I have created a new V.Directory pointing to the service home directory, modified the V.Dir settings to work with ASP.Net 2 and created an application + execute scripts only. The V.Dir runs with anonymous access (regular anonymous user)

I am keep getting the following exception when running the "GetProjects" equivalent:

System.ServiceModel.Security.SecurityNegotiationException: Secure channel cannot be opened because security negotiation with the remote endpoint has failed. This may be due to absent or incorrectly specified EndpointIdentity in the EndpointAddress used to create the channel. Please verify the EndpointIdentity specified or implied by the EndpointAddress correctly identifies the remote endpoint. ---> System.ServiceModel.FaultException: The request for security token has invalid or malformed elements.

at System.ServiceModel.Security.SecurityUtils.ThrowIfNegotiationFault(Message message, EndpointAddress target)

at System.ServiceModel.Security.SspiNegotiationTokenProvider.GetNextOutgoingMessageBody(Message incomingMessage, SspiNegotiationTokenProviderState sspiState)

--> When using the visual studio internal web server I am getting past this point but I fail with the following exception:

Invalid token for impersonation - it cannot be duplicated

This it thrown in the WcfProxy.cs file when running:

WcfResponse response = svr.Create(new CreateRequest(objectType, criteria, context));

 

I think this is due to some security settings either on IIS (BTW - using IIS6 on Windows 2003 Server) - Any help will be greatly appreciated!!!

 

RockfordLhotka replied on Thursday, January 03, 2008

It could be due to WCF security too. I have found security to be the single biggest roadblock to using WCF...

One easy solution is to turn of WCF security in your <system.serviceModel> section

    <bindings>
      <wsHttpBinding>
        <binding name="Transport">
          <security mode="Transport">
            <transport clientCredentialType="None"/>
          </security>
        </binding>
        <binding name="NoSecurity">
          <security mode="None"/>
        </binding>
      </wsHttpBinding>
    </bindings>

Or to explicitly set security to what you need - though figuring out even basic security configurations is really tough... I'm still trying to get the darn thing to allow me to use SSL but not to pass the Windows identity over the wire at the same time...

shaih replied on Sunday, January 06, 2008

Hi Rocky,

I have tried your suggestion with no luck.

I have also tried to run the ProjectTracker example with the same result. To run the example I performed the following:

1. I have added the PTWcfClient, PTWcfServiceAuth and PTWcfService projects/websites to the Project Trackercs solution and compiled it.

2. Added a virtual directory under the IIS default web site, created an application and changed the website to run with .Net 2 instead of .Net 1.

3. When running the PTWcfClient I am getting the same following exception (This is thrown on the "

PTWcfService.ProjectData[] list = svc.GetProjectList();" line):

System.ServiceModel.Security.SecurityNegotiationException: Secure channel cannot be opened because security negotiation with the remote endpoint has failed. This may be due to absent or incorrectly specified EndpointIdentity in the EndpointAddress used to create the channel. Please verify the EndpointIdentity specified or implied by the EndpointAddress correctly identifies the remote endpoint. ---> System.ServiceModel.FaultException: The request for security token has invalid or malformed elements.

at System.ServiceModel.Security.SecurityUtils.ThrowIfNegotiationFault(Message message, EndpointAddress target)

at System.ServiceModel.Security.SspiNegotiationTokenProvider.GetNextOutgoingMessageBody(Message incomingMessage, SspiNegotiationTokenProviderState sspiState)

 

 

Any thing else I have missed to run this example (I am using the cslacs-3.0.3-071127[1].zip)

Thanks

Shai

RockfordLhotka replied on Sunday, January 06, 2008

PTWcfClient is different from using the WCF data portal channel.

 

PTWcfClient has a couple configuration options to support the different scenarios I walk through in the ebook. One scenario is unsecured, the other passes username/password credentials to the server over an encrypted channel.

 

Both client and server need to agree on the security model or you’ll get errors like the one you have.

 

One thing you can try is to right-click on the service reference in PTWcfClient and tell it to refresh/update the reference. That’ll cause it to re-read the WSDL from the service and recreate the client-side config. Once you’ve done that it should work.

 

If that does not work, then the service is configured to require some sort of security you aren’t providing. It is probably configured (in whole or part) to require the encrypted channel and/or the username/password credentials.

 

As I say, configuring WCF security is really unpleasant. Read carefully through the WCF security section of the ebook, and read the security chapter in Juval Lowy’s Programming WCF Services book, and read the MSDN content on WCF security. And remember that the config files are case-sensitive.

 

I find dark humor in all this. One major support issue I’ve always had with CSLA is configuring remoting – mostly because it is so easy to do a typo in the config files. Along comes WCF, which is “superior” to remoting, with far more complex configuration. Microsoft’s “move forward” is (in this case at least) a big move backward if you ask me…

 

Though to be fair, there is a Microsoft GUI tool you can use to manipulate the WCF config sections. And you may consider using that to view/edit both config files because it might help you identify how they are mismatched. Here’s some info on that tool: http://jeffbarnes.net/portal/blogs/jeff_barnes/archive/2007/02/28/wcf-configuration-editor.aspx

 

Rocky

 

 

From: shaih [mailto:cslanet@lhotka.net]
Sent: Sunday, January 06, 2008 8:19 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Wcf issues - IIS and VS internal web server

 

Hi Rocky,

I have tried your suggestion with no luck.

I have also tried to run the ProjectTracker example with the same result. To run the example I performed the following:

1. I have added the PTWcfClient, PTWcfServiceAuth and PTWcfService projects/websites to the Project Trackercs solution and compiled it.

2. Added a virtual directory under the IIS default web site, created an application and changed the website to run with .Net 2 instead of .Net 1.

3. When running the PTWcfClient I am getting the same following exception (This is thrown on the "

PTWcfService.ProjectData[] list = svc.GetProjectList();" line):

System.ServiceModel.Security.SecurityNegotiationException: Secure channel cannot be opened because security negotiation with the remote endpoint has failed. This may be due to absent or incorrectly specified EndpointIdentity in the EndpointAddress used to create the channel. Please verify the EndpointIdentity specified or implied by the EndpointAddress correctly identifies the remote endpoint. ---> System.ServiceModel.FaultException: The request for security token has invalid or malformed elements.

at System.ServiceModel.Security.SecurityUtils.ThrowIfNegotiationFault(Message message, EndpointAddress target)

at System.ServiceModel.Security.SspiNegotiationTokenProvider.GetNextOutgoingMessageBody(Message incomingMessage, SspiNegotiationTokenProviderState sspiState)

 

 

Any thing else I have missed to run this example (I am using the cslacs-3.0.3-071127[1].zip)

Thanks

Shai



shaih replied on Wednesday, January 09, 2008

Hi Rocky,

Thanks for your help, after hard work I was able to make both the ProjectTracker and my application work with the custom security defined.

I am not clear though on the service side - should a login call be made on each call to the service? Or is it supposed to be managed by the WCF once the configuration files define the custom validator? After debugging the service I have noticed that the PrincipalPolicy Evaluate is called with my Windows identity and the CredentialValidator Validate is not called

Any thing I missed - I did not find anything in the CSLA .Net 3 eBook on this

 

Thanks

RockfordLhotka replied on Wednesday, January 09, 2008

I chose not to cover Windows security in the 3.0 book, because that’s the one topic that is covered in every WCF book I’ve looked at. While passing a custom username/password is covered in none of the books I have found, so I was able to cover new (and important) ground.

 

It makes total sense that your credential validator wouldn’t be called – you can’t validation the Windows credentials, and so WCF defers to Windows in that case.

 

But it makes sense that the policy evaluation would be called, because WCF is claims-based and they need to allow you to create the appropriate set of claims/roles based on the Windows user (because Windows credentials have no built-in claims).

 

You should be able to implement the policy evaluation class as shown in the 3.0 ebook, and use that location to create your custom principal based on the username of the validated credential provided by WCF.

 

In the end, no, you should not need to call a login method in each service implementation - though honestly I think that might be easier than implementing the credential validator and policy evaluator... WCF does have an impressive extensibility model, but it isn’t easy.

 

Rocky

 

From: shaih [mailto:cslanet@lhotka.net]
Sent: Wednesday, January 09, 2008 7:56 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: Wcf issues - IIS and VS internal web server

 

Hi Rocky,

Thanks for your help, after hard work I was able to make both the ProjectTracker and my application work with the custom security defined.

I am not clear though on the service side - should a login call be made on each call to the service? Or is it supposed to be managed by the WCF once the configuration files define the custom validator? After debugging the service I have noticed that the PrincipalPolicy Evaluate is called with my Windows identity and the CredentialValidator Validate is not called

Any thing I missed - I did not find anything in the CSLA .Net 3 eBook on this

 

Thanks



shaih replied on Wednesday, January 09, 2008

Hi Rocky and thanks for the quick reply,

I think I was not clear in my previous thread. I am using custom credentials - for the matter of question I am running the project Tracker example after implementing the security configurations in the ebook (certificate, custom authentication code and configuration changes).

The GetProjects method returns all the projects from the database when using for example the "pm" user and "pm" password, but it also returns the project data in case I deliberately send a wrong password for the pm user name.

I have commented the logout call in the service GetProperties method as instructed in the comment above:  //TODO: comment out the following if using the PTWcfServiceAuth components to require a username/password from the caller

My question was - should I replace the logout call with a login call or something else I might have done incorrectly to make this work - the above was tries with the Project tracker example (client and service)

Thanks

Shai

RockfordLhotka replied on Wednesday, January 09, 2008

If you are using the username/password technique from the book then the credential validator should be called. If it is not being called then it is likely that the issue is in your server’s web.config. You need to ensure that the config tells WCF to use both the credential and policy classes you’ve created.

 

Rocky

 

 

From: shaih [mailto:cslanet@lhotka.net]
Sent: Wednesday, January 09, 2008 9:04 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: RE: Wcf issues - IIS and VS internal web server

 

Hi Rocky and thanks for the quick reply,

I think I was not clear in my previous thread. I am using custom credentials - for the matter of question I am running the project Tracker example after implementing the security configurations in the ebook (certificate, custom authentication code and configuration changes).

The GetProjects method returns all the projects from the database when using for example the "pm" user and "pm" password, but it also returns the project data in case I deliberately send a wrong password for the pm user name.

I have commented the logout call in the service GetProperties method as instructed in the comment above:  //TODO: comment out the following if using the PTWcfServiceAuth components to require a username/password from the caller

My question was - should I replace the logout call with a login call or something else I might have done incorrectly to make this work - the above was tries with the Project tracker example (client and service)

Thanks

Shai



rajeshvar replied on Thursday, June 12, 2008

Thanks a lot Rocky,

Your solution got me working after 8 hours of struggling.

Where can I read more about security, next phase I have to implement SSL for the same.

Thanks,

Rajesh

RockfordLhotka replied on Thursday, June 12, 2008

Thankfully the Microsoft Patterns and Practices group just got a beta of their WCF security guidance out at http://www.codeplex.com /wcfsecurityguide.

This is probably the single best resource for WCF security information available today.

JoeFallon1 replied on Thursday, June 12, 2008

Rocky's link did not work for me.

Here is another one:

http://www.codeplex.com/Project/ProjectDirectory.aspx?ProjectSearchText=wcfsecurityguide

 

mr_fuku replied on Wednesday, February 18, 2009

Hey Rocky:

I've tried your suggestion of altering the <wsHttpBinding> sections of both the web and app config files in an attempt to get the PtWcfClient project working.

However, the error message I'm now getting is:

System.ServiceModel.Security.SecurityNegotiationException was unhandled
  Message="Secure channel cannot be opened because security negotiation with the remote endpoint has failed.
  This may be due to absent or incorrectly specified EndpointIdentity in the EndpointAddress used to create the channel.
  Please verify the EndpointIdentity specified or implied by the EndpointAddress correctly identifies the remote endpoint. "
  Source="mscorlib"
  StackTrace:
    Server stack trace:
       at System.ServiceModel.Security.IssuanceTokenProviderBase`1.DoNegotiation(TimeSpan timeout)
       at System.ServiceModel.Security.SspiNegotiationTokenProvider.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Security.CommunicationObjectSecurityTokenProvider.Open(TimeSpan timeout)
       at System.ServiceModel.Security.SecurityUtils.OpenTokenProviderIfRequired(SecurityTokenProvider tokenProvider, TimeSpan timeout)
       at System.ServiceModel.Security.SymmetricSecurityProtocol.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Security.WrapperSecurityCommunicationObject.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.SecurityChannelFactory`1.ClientSecurityChannel`1.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.DoOperation(SecuritySessionOperation operation, EndpointAddress target, Uri via, SecurityToken currentToken, TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionSecurityTokenProvider.GetTokenCore(TimeSpan timeout)
       at System.IdentityModel.Selectors.SecurityTokenProvider.GetToken(TimeSpan timeout)
       at System.ServiceModel.Security.SecuritySessionClientSettings`1.ClientSecuritySessionChannel.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.OnOpen(TimeSpan timeout)
       at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.CallOpenOnce.System.ServiceModel.Channels.ServiceChannel.ICallOnce.Call(ServiceChannel channel, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.CallOnceManager.CallOnce(TimeSpan timeout, CallOnceManager cascade)
       at System.ServiceModel.Channels.ServiceChannel.EnsureOpened(TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs, TimeSpan timeout)
       at System.ServiceModel.Channels.ServiceChannel.Call(String action, Boolean oneway, ProxyOperationRuntime operation, Object[] ins, Object[] outs)
       at System.ServiceModel.Channels.ServiceChannelProxy.InvokeService(IMethodCallMessage methodCall, ProxyOperationRuntime operation)
       at System.ServiceModel.Channels.ServiceChannelProxy.Invoke(IMessage message)
    Exception rethrown at [0]:
       at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
       at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
       at PTWcfClient.PTWcfService.IPTService.GetRoles(RoleRequest request)
       at PTWcfClient.PTWcfService.PTServiceClient.GetRoles(RoleRequest request) in c:\documents and settings\tduncan\my documents\csla\samples\cslanet\cs\projecttrackercs\ptwcfclient\service references\ptwcfservice\reference.cs:line 584
       at PTWcfClient.Form2.Form2_Load(Object sender, EventArgs e) in C:\Documents and Settings\tduncan\My Documents\csla\samples\CslaNet\cs\ProjectTrackercs\PTWcfClient\Form2.cs:line 28
       at System.Windows.Forms.Form.OnLoad(EventArgs e)
       at System.Windows.Forms.Form.OnCreateControl()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.WmShowWindow(Message& m)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
       at System.Windows.Forms.ContainerControl.WndProc(Message& m)
       at System.Windows.Forms.Form.WmShowWindow(Message& m)
       at System.Windows.Forms.Form.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)
       at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
       at System.Windows.Forms.Control.set_Visible(Boolean value)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.RunDialog(Form form)
       at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
       at PTWcfClient.MainForm.RoleListButton_Click(Object sender, EventArgs e) in C:\Documents and Settings\tduncan\My Documents\csla\samples\CslaNet\cs\ProjectTrackercs\PTWcfClient\MainForm.cs:line 26
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at PTWcfClient.Program.Main() in C:\Documents and Settings\tduncan\My Documents\csla\samples\CslaNet\cs\ProjectTrackercs\PTWcfClient\Program.cs:line 17
       at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: System.ServiceModel.FaultException
       Message="The request for security token has invalid or malformed elements."
       Source="System.ServiceModel"
       Action="http://www.w3.org/2005/08/addressing/soap/fault"
       StackTrace:
            at System.ServiceModel.Security.SecurityUtils.ThrowIfNegotiationFault(Message message, EndpointAddress target)
            at System.ServiceModel.Security.SspiNegotiationTokenProvider.GetNextOutgoingMessageBody(Message incomingMessage, SspiNegotiationTokenProviderState sspiState)
       InnerException:

Any suggestions?

Thanks!
Ted

Copyright (c) Marimer LLC