I have a WCF web service and I call the WCF method with Ajax
(JQuery
).
I tested my web service with WcfTestClient.exe
and it works well.
But when I call the web service method with Jquery
, I have an error (object reference not set to an instance of an object).
I debug and I have this in my **ConfigurationManager.ConnectionStrings[0].Name** : *LocalSqlServer*
.
My dataBase key is RMS and not LocalSqlServer.
I have 2 projects in my solution, the WCF and an application console that will do to turn back the web service.
Here my solution
Here is my web.config :
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<connectionStrings>
<add name="RMS" connectionString="Data Source=192.168.40.137;Initial Catalog=RMS_Database;Persist Security Info=True;User ID=****;Password=****"
providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" maxRequestLength="16384"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="basicHttp" allowCookies="true" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000">
<readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000"/>
</binding>
</basicHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
I created a .asmx
web service and I succeeded JQuery
calls.
I think my solution is not using the correct web.config.
How to solve this?
I solved the problem.
I also added the connectionstrings in app.config of the GettingStartedHost project and now it works well.
Is this the right way?