I have a simple Custom Service Application that hosts a WCF service. the service has a simple method
[ServiceContract] [XmlSerializerFormat] public interface IWCFServiceContract { [OperationContract] Client GetClient(int clientId); [OperationContract] DateTime GetCurrentDateTime(); }
service app methods look like this:
public Client GetClient(int clientId) { try { MonitoringDBDataContext ctx = new MonitoringDBDataContext(Database.DatabaseConnectionString); return (from c in ctx.Clients where c.Id == clientId select c).Single(); } catch (Exception ex) { SPDiagnosticsService.Local.WriteTrace(0, new SPDiagnosticsCategory("xxxx", TraceSeverity.Unexpected, EventSeverity.Error), TraceSeverity.Unexpected, ex.Message, ex.StackTrace); throw new FaultException(new FaultReason(ex.Message), new FaultCode(ex.InnerException.Message)); } } public DateTime GetCurrentDateTime() { return DateTime.Now; }
From a client console application, I call the GetCurrentTime() method and it fails with "The service implementation object was not initialized or is not available". My client code is:
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(delegate { return true; }); DataContext _dc = new DataContext(); using (WCFServiceContractClient _ctx = new WCFServiceContractClient()) { _ctx.ClientCredentials.Windows.ClientCredential = new NetworkCredential("xxxx", "xxxxx", "xxxx"); //Client client = _ctx.GetClient(1); DateTime time = _ctx.GetCurrentDateTime(); }
i can do a _ctx.Open() with no issues, but when i call that very simple method, it fails. do note that im calling this over https. my bindings seem correct. but im accessing through a web app that has both http and extended to https. i expect to either use both http and https or just https.