Click here to Skip to main content
15,389,797 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 'http://tempuri.org/ICustomService/GetCurrencyData’ 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.

C#
[ServiceContract]
  public interface ICustomService {
    [OperationContract]
    ConversionData GetCurrencyData(ConversionData conversionData);

    [OperationContract]
    bool AuthenticateUser(string userName, string password);

  }


Created an endpoint with wsHttpBinding.

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


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

C#
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());
      factory.Open();
      EndpointAddress address = new EndpointAddress("http://localhost/ConversionAgents/CustomService/");
      IRequestChannel irc = factory.CreateChannel(address);
      string request = String.Empty;
      using (irc as IDisposable) {
        irc.Open();
        request = String.Format(@"<GetCurrencyData xmlns='http://tempuri.org/'>
                                        <conversionData xmlns:d4p1='http://schemas.datacontract.org/2004/07/ConversionAgents' 
                                          xmlns:i='http://www.w3.org/2001/XMLSchema-instance'>	                                   
	                                        <d4p1:ConversionDate>{0}</d4p1:ConversionDate>
	                                        <d4p1:CovertedAmount>{1}</d4p1:CovertedAmount>
                                          <d4p1:FromCurrency>{2}</d4p1:FromCurrency>
                                          <d4p1:Password>{6}</d4p1:Password>
                                          <d4p1:SourceAmount>{3}</d4p1:SourceAmount>
                                          <d4p1:ToCurrency>{4}</d4p1:ToCurrency>
                                          <d4p1:UserName>{5}</d4p1:UserName>                                          
                                        </conversionData>
                                    </GetCurrencyData>", XmlConvert.ToString(DateTime.Now, XmlDateTimeSerializationMode.Local), "",
                           "USD",
                           "1",
                           "INR", "admin", "demo");

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

        Message m = Message.CreateMessage(MessageVersion.Soap12WSAddressing10,
                    "http://tempuri.org/ICustomService/GetCurrencyData", reader);

        Message ret = irc.Request(m);
        reader.Close();

        Console.WriteLine(ret);
        Console.ReadLine();
      }

      //close the factory
      factory.Close();

    }
Posted
Updated 8-Jun-15 8:15am
v2

1 solution

Use HttpBinding instead of wsHttpBinding, there is a feature in app config to set secc]urity as none
   
Comments
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