Click here to Skip to main content
15,569,696 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a WCF Library project ConversionAgents and test client

Now while executing the solution I am getting error.
“The message could not be processed. This is most likely because the action '’ 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.”

Question : Please let me know what wrong in below logic to call the service by creating endpoint dynamically.

  public interface ICustomService {
    ConversionData GetCurrencyData(ConversionData conversionData);

    bool AuthenticateUser(string userName, string password);


Created an endpoint with wsHttpBinding.

<service name="CurrencyConversionAgents.CustomService">
        <endpoint address="" binding="wsHttpBinding"  bindingName="wsMessage" contract="CurrencyConversionAgents.ICustomService">
            <dns value="localhost" />
        <endpoint address="mex" binding="mexHttpBinding" name="Mex" contract="IMetadataExchange" />
            <add baseAddress="http://localhost/ConversionAgents/CustomService/" />
        <binding name ="wsMessage">
          <security mode ="None">

Now created a test client shown below to call this service using IChannelFactory.

namespace TestClient {
  class Program {
    static void Main(string[] args) {

      WSHttpBinding binding = new WSHttpBinding(SecurityMode.None);
      //binding.ReliableSession =
      IChannelFactory<IRequestChannel> factory = binding.BuildChannelFactory<IRequestChannel>(
         new BindingParameterCollection());
      EndpointAddress address = new EndpointAddress("http://localhost/ConversionAgents/CustomService/");
      IRequestChannel irc = factory.CreateChannel(address);
      string request = String.Empty;
      using (irc as IDisposable) {
        request = String.Format(@"<GetCurrencyData xmlns=''>
                                        <conversionData xmlns:d4p1='' 
                                    </GetCurrencyData>", XmlConvert.ToString(DateTime.Now, XmlDateTimeSerializationMode.Local), "",
                           "INR", "admin", "demo");

        XmlReader reader = XmlReader.Create(new StringReader(request));

        Message m = Message.CreateMessage(MessageVersion.Soap12WSAddressing10,
                    "", reader);

        Message ret = irc.Request(m);


      //close the factory

Updated 8-Jun-15 9:15am

1 solution

Use HttpBinding instead of wsHttpBinding, there is a feature in app config to set secc]urity as none
Share this answer
Pax125 19-Feb-18 23:21pm    
But what if I need wsHttpBinding? There is send and receive here.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900