System.ServiceModel.Security.SecurityNegotiationException, in WSCF/WCF

BizTalk Utilities CV ,   Jobs ,   Code library
 
Go to the front page to continue learning about XML or select below:

Contents

Recent WSCF/WCF posts

\r\n problem with SOAP and XmlDocument
WCF Service Validating Soap Header Username/Password
WCF Inbound Message
Username and Password validation in wcf adapter
How to provide custom WSDL from a WCF server
WCF security question
Best Practices - most forward looking
WCF authentication problems
XML attributes
Migration path from WSE 2.0 (SP3) to WCF

 
 

WSCF/WCF

View :   

Latest Topics

Table Of Contents


Post Reply

System.ServiceModel.Security.SecurityNegotiationException

All posts: microsoft.public.dotnet.framework.webservices
Source: microsoft.public.dotnet.framework.webservices
Sent date: 05/21/2008
From: Manjree Garg
Message:

Hi,

I created a web service and hosted it in Windows Services. It is working
fine. Now I am trying to implement the X509 certificates for message layer
security. But it is throwing the following exception:

An unhandled exception of type
'System.ServiceModel.Security.SecurityNegotiationException' occurred in
mscorlib.dll

Additional information: 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.


The WinSvchost file is:



namespace PreprocessingWinSvcHost
{
public partial class PreprocessingWinSvc : ServiceBase
{
private ServiceHost myHost;
public PreprocessingWinSvc()
{
InitializeComponent();
}

protected override void OnStart(string[] args)
{
try
{
//Create the host.

Uri address = new
Uri("http://localhost:8080/PreprocessingService");
WSHttpBinding binding = new WSHttpBinding();
Type contract = typeof(IPreprocess);

binding.MaxBufferPoolSize = 200000000;
binding.MaxReceivedMessageSize = 200000000;
binding.Name = "WSHttpBinding_IPreprocess";

binding.Security.Mode = SecurityMode.Message;
binding.Security.Message.ClientCredentialType =
MessageCredentialType.Certificate;

myHost = new ServiceHost(typeof(PreprocessingService));
myHost.AddServiceEndpoint(contract, binding, address);

myHost.Credentials.ServiceCertificate.SetCertificate(
StoreLocation.LocalMachine, StoreName.My,
X509FindType.FindBySubjectName, "windowshost");

ClientCredentials creds = new ClientCredentials();
// Configure peer trust.

creds.ServiceCertificate.Authentication.CertificateValidationMode =
X509CertificateValidationMode.PeerOrChainTrust;

//Creates an output file.
Stream MyOutputFile =
File.Create("c:\\checklog\\Logfile1.txt");
TextWriterTraceListener TextListener1 = new
TextWriterTraceListener(MyOutputFile);
Trace.Listeners.Add(TextListener1); //Add a listner to the
Trace.

// Writes output message to the output file and to a console
screen.
Trace.WriteLine(DateTime.Now.ToLongTimeString() + " -
Service starting...");


myHost.Open();

Trace.WriteLine("state = "+ myHost.State);

// Flush and close the output file.
Trace.Flush();
TextListener1.Flush();
TextListener1.Close();
}
catch (Exception e)
{
Console.WriteLine("Message: {0}", e.Message);
}


}

and the Client is:


namespace PreprocessingClient
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("**** Preprocessing Client ****");
EndpointAddress address = new
EndpointAddress("http://localhost:8080/PreprocessingService");
WSHttpBinding binding = new WSHttpBinding();
binding.MaxBufferPoolSize = 200000000;
binding.MaxReceivedMessageSize = 200000000;
System.ServiceModel.ChannelFactory<IPreprocess> cf =
new System.ServiceModel.ChannelFactory<IPreprocess>(binding,
address);
cf.Credentials.ClientCertificate.SetCertificate(
StoreLocation.LocalMachine, StoreName.My,
X509FindType.FindBySubjectName, "WCFUser");
cf.Credentials.ServiceCertificate.SetDefaultCertificate(
StoreLocation.LocalMachine, StoreName.My,
X509FindType.FindBySubjectName,"windowshost");
IPreprocess proxy = cf.CreateChannel();
// PreprocessClient proxy = new PreprocessClient();
//proxy.Open(); //open the client's proxy

proxy.EnableMatGui(false);
}


The app.config for the client is :


<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IPreprocess"
closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00"
sendTimeout="00:40:00"
bypassProxyOnLocal="false" transactionFlow="false"
hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="200000000"
maxReceivedMessageSize="20000000"
messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32"
maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384"
/>
<reliableSession ordered="true"
inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows"
proxyCredentialType="None"
realm="" />
<message clientCredentialType="Certificate"
negotiateServiceCredential="true"
algorithmSuite="Default"
establishSecurityContext="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/PreprocessingService"
binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IPreprocess"
contract="ServiceReference1.IPreprocess"
name="WSHttpBinding_IPreprocess">
<identity>
<servicePrincipalName value="host/Avacta-n31m-1" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>



cheers,

Manjree


Post Reply

Related Messages

Table Of Contents



Other groups

WCF LOB

WSCF/WCF

BizTalk Rule Engine

BizTalk BPM, process

BizTalk BAM, activity

Biztalk Adapters

BizTalk Orchestration

BizTalk Server

WS WSDL

 

    Email TopXML