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.
[ServiceContract]
public interface ICustomService {
[OperationContract]
ConversionData GetCurrencyData(ConversionData conversionData);
[OperationContract]
bool AuthenticateUser(string userName, string password);
}
Created an endpoint with wsHttpBinding.
<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.
namespace TestClient {
class Program {
static void Main(string[] args) {
WSHttpBinding binding = new WSHttpBinding(SecurityMode.None);
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();
}
factory.Close();
}