Share via

SOAP Client: System.InvalidOperationException

Brown, Matt 146 Reputation points
2024-02-26T15:55:15.5733333+00:00

When I run a windows service which is trying to send XML data via SOAP, I am getting this error. Note, this is converted over from a C++ version. I know svcutil is used to generate the C++ code based on other files. I haven't been able to figure out if I'm missing a reference.

Application: ENS_Service.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException
   at System.ServiceModel.Description.ConfigLoader.LoadChannelBehaviors(System.ServiceModel.Description.ServiceEndpoint, System.String)
   at System.ServiceModel.ChannelFactory.ApplyConfiguration(System.String, System.Configuration.Configuration)
   at System.ServiceModel.ChannelFactory.ApplyConfiguration(System.String)
   at System.ServiceModel.ChannelFactory.InitializeEndpoint(System.String, System.ServiceModel.EndpointAddress)
   at System.ServiceModel.ChannelFactory`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor(System.String, System.ServiceModel.EndpointAddress)
   at System.ServiceModel.ConfigurationEndpointTrait`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].CreateSimplexFactory()
   at System.ServiceModel.ConfigurationEndpointTrait`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].CreateChannelFactory()
   at System.ServiceModel.ClientBase`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].CreateChannelFactoryRef(System.ServiceModel.EndpointTrait`1<System.__Canon>)
   at System.ServiceModel.ClientBase`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].InitializeChannelFactoryRef()
   at System.ServiceModel.ClientBase`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor()
   at ENS_Service.Entities.WebServiceWebLogSoapClient..ctor()
   at EnsService.WebLogUploader.ThreadProc()
   at System.Threading.ThreadHelper.ThreadStart_Context(System.Object)
   at System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object)
   at System.Threading.ThreadHelper.ThreadStart()

The SoapClient class is here.

using System.Data;
using System.ServiceModel;
using System.Threading.Tasks;
namespace ENS_Service.Entities
{
    [GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
    public class WebServiceWebLogSoapClient : ClientBase<IWebServiceWebLogSoap>, IWebServiceWebLogSoap
    {
        public WebServiceWebLogSoapClient() {}
        public WebLog_Response UpdateWebLogWithAYSForNotificationId(WebLogHeader webLogHeader, WebLogWS webLog)
        {
            var inValue = new UpdateWebLogWithAYSForNotificationIdRequest();
            inValue.WebLogHeader = webLogHeader;
            inValue.objWebLog = webLog;
            UpdateWebLogWithAYSForNotificationIdResponse retVal = ((IWebServiceWebLogSoap)(this)).UpdateWebLogWithAYSForNotificationId(inValue);
            return retVal.UpdateWebLogWithAYSForNotificationIdResult;
        }
        public AddWebLogResponse AddWebLog(AddWebLogRequest request)
        {
            throw new NotImplementedException();
        }
        public Task<AddWebLogResponse> AddWebLogAsync(AddWebLogRequest request)
        {
            throw new NotImplementedException();
        }
        public DataSet GetRecentWebLog(int top)
        {
            throw new NotImplementedException();
        }
        public Task<DataSet> GetRecentWebLogAsync(int top)
        {
            throw new NotImplementedException();
        }
        public DataSet GetWebLog(int refNum)
        {
            throw new NotImplementedException();
        }
        public Task<DataSet> GetWebLogAsync(int refNum)
        {
            throw new NotImplementedException();
        }
        public UpdateWebLogWithAYSForNotificationIdResponse UpdateWebLogWithAYSForNotificationId(UpdateWebLogWithAYSForNotificationIdRequest request)
        {
            throw new NotImplementedException();
        }
        public Task<UpdateWebLogWithAYSForNotificationIdResponse> UpdateWebLogWithAYSForNotificationIdAsync(UpdateWebLogWithAYSForNotificationIdRequest request)
        {
            throw new NotImplementedException();
        }
        public UpdateWebLogWithCmisForNotificationIdResponse UpdateWebLogWithCmisForNotificationId(UpdateWebLogWithCmisForNotificationIdRequest request)
        {
            throw new NotImplementedException();
        }
        public Task<UpdateWebLogWithCmisForNotificationIdResponse> UpdateWebLogWithCmisForNotificationIdAsync(UpdateWebLogWithCmisForNotificationIdRequest request)
        {
            throw new NotImplementedException();
        }
    }
}
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

Answer accepted by question author

Michael Taylor 61,221 Reputation points
2024-02-26T16:25:31.37+00:00

Error is occurring when loading the configuration. Several thoughts here:

  • Does this code work when run locally as a console app?
  • Do you have the configuration file for the service set up to work with your client settings?
  • There is likely an inner exception occurring here that has the details. Dump the root exception + any InnerException values.

If the code works as a console app but not as a service then it is almost always a permission issue. Services don't normally have network access. But I'm not sure that is the problem here.

Was this answer helpful?


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.