Question

I am writing WCF service for silverlight application. In MainService I want to read information from config file. So I want to use ConfigurationManager. I added System.Configuration.dll to project compile and published. Then after call WCF service gets an error, see bellow. If I dont use the ConfigurationManager (no referencing DLL) it is working. Here is part of code to call settings and stored settings in config.

var connectionManagerDatabaseServers = ConfigurationManager.GetSection("ConnectionManagerDatabaseServers") as NameValueCollection;
string config = connectionManagerDatabaseServers["ConnectionString"];

<configSections>
    <section name="ConnectionManagerDatabaseServers" type="System.Configuration.NameValueSectionHandler" />
</configSections>

<ConnectionManagerDatabaseServers>
    <add key="DatabaseType" value="1" />
    <add key="ConnectionString" value="VALUE" />
</ConnectionManagerDatabaseServers>

The server encountered an error processing the request. The exception message is 'Padding is invalid and cannot be removed.'. See server logs for more details. The exception stack trace is:

at System.Security.Cryptography.RijndaelManagedTransform.DecryptData(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount, Byte[]& outputBuffer, Int32 outputOffset, PaddingMode paddingMode, Boolean fLast) at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount) at System.Security.Cryptography.CryptoStream.FlushFinalBlock() at System.Security.Cryptography.CryptoStream.Dispose(Boolean disposing) at System.IO.Stream.Close() at System.IO.Stream.Dispose() at GX.Framework.Utils.Encryption.Decrypt(String encryptedText) at ServiceWCF.MainService..ctor() at CreateServiceWCF.MainService() at System.ServiceModel.Dispatcher.InstanceProvider.GetInstance(InstanceContext instanceContext, Message message) at System.ServiceModel.Dispatcher.InstanceBehavior.GetInstance(InstanceContext instanceContext, Message request) at System.ServiceModel.InstanceContext.GetServiceInstance(Message message) at System.ServiceModel.Dispatcher.InstanceBehavior.EnsureServiceInstance(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage41(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage4(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage31(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage3(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage2(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage11(MessageRpc& rpc) at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessage1(MessageRpc& rpc) at System.ServiceModel.Dispatcher.MessageRpc.Process(Boolean isOperationContextSet)

Was it helpful?

Solution 2

I resolved Exception! Problem was in constructor of service. In constructor I had a mistake in one method. So now its working. Sorry for publish this mistake.

OTHER TIPS

Musketyr, config file must named Web.config

    <configuration>
      <appSettings>
        <add key="DatabaseType" value="1" />
        <add key="ConnectionString" value="VALUE" />
      </appSettings>
      ...


    try this
    [WebMethod]
    public string GetString()
    {
      return ConfigurationManager.AppSettings["ConnectionString"].ToString();
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top