Link to home
Start Free TrialLog in
Avatar of copyPasteGhost
copyPasteGhostFlag for Canada

asked on

WCF IIS ProtocolException

I have a WCF Service hosted on a win 2K3 server. .NET 3.5 is installed on the server as well as the windows server 2008 SDK for .NET 3.5.

I am able to see the service through VS 2008 when I right click to add a service reference. That part is all good and dandy and even my intellisense is working perfectly. The problem I'm having is when I run the web application and try to call the wCF service. I'm getting this error.

System.ServiceModel.Security.SecurityNegotiationException was unhandled by user code
  Message="The caller was not authenticated by the service."
  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 ServiceReference1.IService1.GetDataUsingDataContract(CompositeType composite, String key)
       at ServiceReference1.Service1Client.GetDataUsingDataContract(CompositeType composite, String key) in d:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\orderwcftest\f384daf1\a4aca58d\App_WebReferences.uahcqvgq.1.cs:line 122
       at _Default.btnHitService_Click(Object sender, EventArgs e) in d:\Inetpub\wwwroot\OrderWCFTest\Default.aspx.cs:line 16
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: System.ServiceModel.FaultException
       Message="The request for security token could not be satisfied because authentication failed."
       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:


I did some research and I came across a post saying that if you change your web.config of the asp.net application from:

<reliableSession ordered="true" inactivityTimeout="00:10:00"
      enabled="False" />
     <security mode="Message">

to

<reliableSession ordered="true" inactivityTimeout="00:10:00"
      enabled="true" />
     <security mode="None">

it should solve that problem. So I did that and now when I try to hit the WCF service I'm getting this error.

System.ServiceModel.ProtocolException was unhandled by user code
  Message="The remote endpoint has sent an unrecognized fault with namespace, http://www.w3.org/2003/05/soap-envelope, name Sender, and reason The message could not be processed. This is most likely because the action 'http://schemas.xmlsoap.org/ws/2005/02/rm/CreateSequence' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.. The channel could not be opened."
  Source="mscorlib"
  StackTrace:
    Server stack trace:
       at System.ServiceModel.Channels.ClientReliableSession.ProcessCreateSequenceResponse(Message response, DateTime start)
       at System.ServiceModel.Channels.ClientReliableSession.Open(TimeSpan timeout)
       at System.ServiceModel.Channels.ReliableRequestSessionChannel.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 ServiceReference1.IService1.GetDataUsingDataContract(CompositeType composite, String key)
       at ServiceReference1.Service1Client.GetDataUsingDataContract(CompositeType composite, String key) in d:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\orderwcftest\f384daf1\a4aca58d\App_WebReferences.uahcqvgq.1.cs:line 122
       at _Default.btnHitService_Click(Object sender, EventArgs e) in d:\Inetpub\wwwroot\OrderWCFTest\Default.aspx.cs:line 16
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:


I've tried to find out why, and came up empty.

Any help would be AWESOME!!!!

Thanks,
Ghost
Avatar of copyPasteGhost
copyPasteGhost
Flag of Canada image

ASKER

New error:

Now I'm getting this:

System.ServiceModel.FaultException was unhandled by user code
  Message="The message could not be processed. This is most likely because the action 'http://tempuri.org/IService1/GetDataUsingDataContract' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding."
  Source="mscorlib"
  StackTrace:
    Server stack trace:
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       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 ServiceReference1.IService1.GetDataUsingDataContract(CompositeType composite, String key)
       at ServiceReference1.Service1Client.GetDataUsingDataContract(CompositeType composite, String key) in d:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\orderwcftest\f384daf1\a4aca58d\App_WebReferences.31dcjldp.1.cs:line 122
       at _Default.btnHitService_Click(Object sender, EventArgs e) in d:\Inetpub\wwwroot\OrderWCFTest\Default.aspx.cs:line 16
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:

This looks alot like my previous error...This might provide more clues...
Please make sure you define a namespace for the service contract.
   <ServiceContract(Namespace:="http://ExpertsExchange.Answers.ServiceContracts/2009/02", Name:="MyServiceContract", SessionMode:=SessionMode.Allowed)> _

Then use this namespace as bindingNamespace in service endpoints in both web.config files.
       <endpoint name="Basic_HttpBinding_MyContract" address="" binding="basicHttpBinding"
          bindingNamespace="http://ExpertsExchange.Answers.ServiceContracts/2009/02"
          contract="MyServiceContracts">
        </endpoint>
Does the namespace of the servicecontract have to be the namespace of the class?

Ex.
namespace OrderWCF {
   // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
   [ServiceContract]
   public interface IService1 {
}
}

Does the namespace have to be OrderWFC?

Also. >>Please make sure you define a namespace for the service contract.

Where do I put that?


>>

Then use this namespace as bindingNamespace in service endpoints in both web.config files.

In the web.config of the service:

<services>
         <service name="OrderWCF.Service1" behaviorConfiguration="OrderWCF.Service1Behavior">
            <!-- Service Endpoints -->
            <endpoint bindingNamespace="ENTER IN NAMESPACE" address="" binding="wsHttpBinding" contract="OrderWCF.IService1" />
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
         </service>
      </services>

In the Web.config of my localhost website.

<endpoint address="http://admin.testserver.ca/OrderWCF/Service1.svc"
    binding="wsHttpBinding" bindingNamespace="ENTER IN NAMESPACE" bindingConfiguration="WSHttpBinding_IService1"
    contract="ServiceReference1.IService1" name="WSHttpBinding_IService1">

Is this right?
Does the namespace of the servicecontract have to be the namespace of the class?
  No need where class namespace can be EE.Answers.WCF, but service contract namespace can be "http://ExpertsExchange.Answers.ServiceContracts/2009/02".

Does the namespace have to be OrderWFC?
  No need, you can have any namespace defined in the service contract and it must be the same in service configuration in web.config as below.
       <endpoint name="Basic_HttpBinding_MyContract" address="" binding="basicHttpBinding"
          bindingNamespace="http://ExpertsExchange.Answers.ServiceContracts/2009/02"
          contract="MyServiceContracts">
        </endpoint>

Also. >>Please make sure you define a namespace for the service contract.
Where do I put that?
    You define the ServiceContract in your class.
    eg.    [ServiceContract]
             public interface IService1
Here is the web.config for my Service

<?xml version="1.0"?>
<configuration>
   <system.serviceModel>
      <services>
         <service behaviorConfiguration="OrderWCF.Service1Behavior" name="OrderWCF.Service1">
            <clear />
            <endpoint address="" binding="wsHttpBinding" name="OrderService"
               bindingNamespace="http://ExpertsExchange.Answers.ServiceContracts/2009/02"
               contract="OrderWCF.IService1" listenUriMode="Explicit">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
               listenUriMode="Explicit">
            </endpoint>
         </service>
      </services>
      <behaviors>
         <serviceBehaviors>
            <behavior name="OrderWCF.Service1Behavior">
               <serviceMetadata httpGetEnabled="true"/>
               <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
         </serviceBehaviors>
      </behaviors>
   </system.serviceModel>
</configuration>

Anything missing?


This is the WEb.config for my webapplication....

<system.serviceModel>
            <diagnostics>
   <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
  </diagnostics>
  <bindings>
   <wsHttpBinding>
    <binding name="OrderService" closeTimeout="00:01:00" openTimeout="00:01:00"
     receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
     transactionFlow="false" hostNameComparisonMode="StrongWildcard"
     maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 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="None">
      <transport clientCredentialType="Windows" proxyCredentialType="None"
       realm="" />
      <message clientCredentialType="Windows" negotiateServiceCredential="true"
       algorithmSuite="Default" establishSecurityContext="true" />
     </security>
    </binding>
    <binding name="OrderService1" closeTimeout="00:01:00" openTimeout="00:01:00"
     receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
     transactionFlow="false" hostNameComparisonMode="StrongWildcard"
     maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 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="None">
      <transport clientCredentialType="Windows" proxyCredentialType="None"
       realm="" />
      <message clientCredentialType="Windows" negotiateServiceCredential="true"
       algorithmSuite="Default" establishSecurityContext="true" />
     </security>
    </binding>
   </wsHttpBinding>
  </bindings>
            <client>
   <endpoint address="http://admin.getwithit.ca/OrderWCF/Service1.svc"
    binding="wsHttpBinding" bindingConfiguration="OrderService" contract="ServiceReference1.IService1"
   
    name="OrderService">
    <identity>
     <servicePrincipalName value="host/cl-t025-231cn" />
    </identity>
   </endpoint>
   <endpoint address="http://localhost:1753/Service1.svc" binding="wsHttpBinding"
    bindingConfiguration="OrderService1" contract="LocalService.IService1"
    name="OrderService1">
    <identity>
     <userPrincipalName value="TECHCENTER-PC\TechCenter1-un" />
    </identity>
   </endpoint>
  </client>
      </system.serviceModel>


My IService1 class looks like this:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

namespace OrderWCF {
   // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
   [ServiceContract]
   public interface IService1 {

      [OperationContract]
      string GetData(int value);

      [OperationContract]
      CompositeType GetDataUsingDataContract(CompositeType composite, string key);

      [OperationContract]
      bool ValidateSender(string key);

      // TODO: Add your service operations here
   }


   // Use a data contract as illustrated in the sample below to add composite types to service operations.
   [DataContract]
   public class CompositeType {
      bool boolValue = true;
      string stringValue = "Hello ";

      [DataMember]
      public bool BoolValue {
         get { return boolValue; }
         set { boolValue = value; }
      }

      [DataMember]
      public string StringValue {
         get { return stringValue; }
         set { stringValue = value; }
      }
   }
}


Do you see anything missing?

When I try to run my code I get this:

Fault Exception:

The message could not be processed. This is most likely because the action 'http://tempuri.org/IService1/GetDataUsingDataContract' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.


Let me reexplain what I'm doing.

I have a service running on our web servers in a different network. I have a wCF service on that machine. I'm trying to call that WCF service to get information from a databse that is located on the same network as our web servers. The database is not accessible from the web so I have no choice but to access it through the web sevrer. I want to have a windows service to be running here on our local network to Hit the WCF service and get the information from our database.

Am I able to connect to the WCF service from my local website running within my local version of IIS? If I type the address to the WCF service in my broswer I am able to see it. And I'm connecting to it when I add a new service reference...I Don't understand why it's giving me to much problems!

Any help would be great thanks.


Ghost
As I mentioned earlier, 'http://tempuri.org/IService1/GetDataUsingDataContract' error comes due to not having a namespace defined in the servicecontract.
So, your class definition should be like,

   [ServiceContract(Namespace = "http://ExpertsExchange.Answers.ServiceContracts/2009/02", Name = "OrderService", SessionMode = SessionMode.Allowed)]
   public interface IService1 {

Got it?
ok I have made the changes...

Note code below.

I'm still getting the same error...

Ideas?

System.ServiceModel.FaultException was unhandled by user code
  Message="The message could not be processed. This is most likely because the action 'http://tempuri.org/IService1/GetDataUsingDataContract' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding."
  Source="mscorlib"
  StackTrace:
    Server stack trace:
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       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 ServiceReference1.IService1.GetDataUsingDataContract(CompositeType composite, String key)
       at ServiceReference1.Service1Client.GetDataUsingDataContract(CompositeType composite, String key) in d:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\orderwcftest\f384daf1\a4aca58d\App_WebReferences.bueqgual.1.cs:line 122
       at _Default.btnHitService_Click(Object sender, EventArgs e) in d:\Inetpub\wwwroot\OrderWCFTest\Default.aspx.cs:line 17
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:

IService1.cs
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
 
namespace OrderWCF {
   // NOTE: If you change the interface name "IService1" here, you must also update the reference to "IService1" in Web.config.
   [ServiceContract(Namespace = "http://ExpertsExchange.Answers.ServiceContracts/2009/02", Name = "OrderService", SessionMode = SessionMode.Allowed)]
   public interface IService1 {
 
      [OperationContract]
      string GetData(int value);
 
      [OperationContract]
      CompositeType GetDataUsingDataContract(CompositeType composite, string key);
 
      [OperationContract]
      bool ValidateSender(string key);
 
      // TODO: Add your service operations here
   }
 
 
   // Use a data contract as illustrated in the sample below to add composite types to service operations.
   [DataContract]
   public class CompositeType {
      bool boolValue = true;
      string stringValue = "Hello ";
 
      [DataMember]
      public bool BoolValue {
         get { return boolValue; }
         set { boolValue = value; }
      }
 
      [DataMember]
      public string StringValue {
         get { return stringValue; }
         set { stringValue = value; }
      }
   }
}
 
Service1.svc.cs
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Data;
using System.Data.SqlClient;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
 
namespace OrderWCF {
   public class Service1 : IService1 {
      public string GetData(int value) {
         return string.Format("You entered: {0}", value);
      }
      public CompositeType GetDataUsingDataContract(CompositeType composite, string key) {
         if (ValidateSender(key)) {
            if (composite.BoolValue) {
               composite.StringValue += " Suffix On the web...";
            }
         }
         else {
            composite.StringValue = "You are not validated!";
         }
         return composite;
      }
   }
}
 
Service web.config
 
<?xml version="1.0"?>
<configuration>
   <system.serviceModel>
      <services>
         <service behaviorConfiguration="OrderWCF.Service1Behavior" name="OrderWCF.Service1">
            <clear />
            <endpoint address="" binding="wsHttpBinding" name="OrderService"
               bindingNamespace="http://ExpertsExchange.Answers.ServiceContracts/2009/02"
               contract="OrderWCF.IService1" listenUriMode="Explicit">
            </endpoint>
            <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"
               listenUriMode="Explicit">
            </endpoint>
         </service>
      </services>
      <behaviors>
         <serviceBehaviors>
            <behavior name="OrderWCF.Service1Behavior">
               <serviceMetadata httpGetEnabled="true"/>
               <serviceDebug includeExceptionDetailInFaults="true"/>
            </behavior>
         </serviceBehaviors>
      </behaviors>
   </system.serviceModel>
</configuration>
 
 
 
THIS IS THE CODE FOR MY LOCAL WEB APPLICATION!!!
 
protected void btnHitService_Click(object sender, EventArgs e) {
      ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
      client.Open();
      ServiceReference1.CompositeType comType = client.GetDataUsingDataContract(
         new ServiceReference1.CompositeType { 
            BoolValue = true,
            StringValue = "WEB1 Service" 
         }, "SampleKey");
      lblAnswer.Text = comType.StringValue;
      client.Close();
   }
 
Web.config for the local WEB APPLICATION
 
<system.serviceModel>
		<diagnostics>
   <messageLogging logMalformedMessages="true" logMessagesAtTransportLevel="true" />
  </diagnostics>
  <bindings>
   <wsHttpBinding>
    <binding name="OrderService" closeTimeout="00:01:00" openTimeout="00:01:00"
     receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
     transactionFlow="false" hostNameComparisonMode="StrongWildcard"
     maxBufferPoolSize="524288" maxReceivedMessageSize="65536" 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="None">
      <transport clientCredentialType="Windows" proxyCredentialType="None"
       realm="" />
      <message clientCredentialType="Windows" negotiateServiceCredential="true"
       algorithmSuite="Default" establishSecurityContext="true" />
     </security>
    </binding>
   </wsHttpBinding>
  </bindings>
		<client>
   <endpoint address="http://getwithit.ca/OrderWCF/Service1.svc"
    binding="wsHttpBinding" bindingConfiguration="OrderService" contract="ServiceReference1.IService1"
    name="OrderService">
    <identity>
     <servicePrincipalName value="host/cl-t025-231cn" />
    </identity>
   </endpoint>
  </client>
	</system.serviceModel>

Open in new window

new info..

I ran it again and now I'm getting this error message..

The message could not be processed. This is most likely because the action 'http://ExpertsExchange.Answers.ServiceContracts/2009/02/OrderService/GetDataUsingDataContract' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding.
Try to increase timeout (receiveTimeout and other timeout as well)...
    <binding name="OrderService" closeTimeout="00:01:00" openTimeout="00:01:00"
     receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false"
   
Does your takes sometime to respond? any data oriented operations happening?
Timeouts changed:

<binding name="OrderService" closeTimeout="01:01:00" openTimeout="01:01:00"
     receiveTimeout="01:10:00" sendTimeout="01:01:00" bypassProxyOnLocal="false"

The service does nothing. We send a string, the service concatenates another string to it and  sends it back.

Getting error:

System.ServiceModel.FaultException was unhandled by user code
  Message="The message could not be processed. This is most likely because the action 'http://ExpertsExchange.Answers.ServiceContracts/2009/02/OrderService/GetDataUsingDataContract' is incorrect or because the message contains an invalid or expired security context token or because there is a mismatch between bindings. The security context token would be invalid if the service aborted the channel due to inactivity. To prevent the service from aborting idle sessions prematurely increase the Receive timeout on the service endpoint's binding."
  Source="mscorlib"
  StackTrace:
    Server stack trace:
       at System.ServiceModel.Channels.ServiceChannel.HandleReply(ProxyOperationRuntime operation, ProxyRpc& rpc)
       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 ServiceReference1.OrderService.GetDataUsingDataContract(CompositeType composite, String key)
       at ServiceReference1.OrderServiceClient.GetDataUsingDataContract(CompositeType composite, String key) in d:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\orderwcftest\f384daf1\a4aca58d\App_WebReferences.3xxxnlnf.1.cs:line 127
       at _Default.btnHitService_Click(Object sender, EventArgs e) in d:\Inetpub\wwwroot\OrderWCFTest\Default.aspx.cs:line 17
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException:
ASKER CERTIFIED SOLUTION
Avatar of Sachintana Dissanayake
Sachintana Dissanayake
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ok So I matched all the binding names and I configured a new basic endpoint and now it works.

I want to try to configure the wsHttpBinding. when I run it I get this error.

System.ServiceModel.Security.SecurityNegotiationException was unhandled by user code
  Message="The caller was not authenticated by the service."
  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 OrderWCF.OrderService.GetDataUsingDataContract(CompositeType composite, String key)
       at OrderWCF.OrderServiceClient.GetDataUsingDataContract(CompositeType composite, String key) in d:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files\orderwcftest\f384daf1\a4aca58d\App_WebReferences.mjt8jjmb.1.cs:line 127
       at _Default.btnHitService_Click(Object sender, EventArgs e) in d:\Inetpub\wwwroot\OrderWCFTest\Default.aspx.cs:line 17
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: System.ServiceModel.FaultException
       Message="The request for security token could not be satisfied because authentication failed."
       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:


How can I authenticate to the service? Almost there..... :)

I got it.

Thanks so much for your help!

Proxy.ClientCredentials.Windows.ClientCredential.UserName = "uname";
Proxy.ClientCredentials.Windows.ClientCredential.Password = "pword";

Ghost