0

I am net to the use of WCF. I have been struggling with the construct of writing to a database using WCF after deployment. I connect to the WCF via a android Application.

The basic construct that I use is that i implement the WCF with database and attempt to ping the WCF that is deployed on a server by entering the IP and the path.

In my WCF I have two functions. One function Returns the Date and the other function writes to a database using LINQ. When I run the function that must return the date in my browser on android via http://10.0.0.14/jonts/WCFService.svc/date I get a response with no problem. The problem comes up when I run the function to write to the database via http://10.0.0.14/jonts/WCFService.svc/write, I get a 400 Error. But when i run http://localhost:58632/WCFService.svc/write from the host machine it write to the database.

I believe that this is cause by the connection string in my .confic file.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0">
      <assemblies>
        <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
      </assemblies>
    </compilation>
  </system.web>
  <system.serviceModel>
   <services>
      <service name="WCF_Connection.WCFService">
        <endpoint address="" behaviorConfiguration="restfulBehavior"
      binding="webHttpBinding" bindingConfiguration="" contract="WCF_Connection.IWCFService" />
        <host>
          <baseAddresses>
            <add baseAddress="http://10.0.0.14/bookservice" />
          </baseAddresses>
        </host>
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="restfulBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
  <connectionStrings>
    <add name="SampleDbEntities" connectionString="metadata=res://*/BooksModel.csdl|res://*/BooksModel.ssdl|res://*/BooksModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\SampleDb.mdf;Integrated Security=True;User Instance=True;MultipleActiveResultSets=True&quot;"
  providerName="System.Data.EntityClient" />
    <add name="jarvisConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\jarvis.mdf;Integrated Security=True"
  providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>

The server with IP 10.0.0.14 is running SQL Server Developer 2012.

1)Is it my connection string causing this error?
2)How can I fix this?
Jonathan
  • 545
  • 1
  • 8
  • 27

1 Answers1

0

1) You're using Integrated Security option in connection strings , so you should check that AppPool in IIS that serves your wcf application is ran under Windows user that has permission to connect your database and perform queries. Or consider to use login/password to specify sql server login (SQL server should be installed with mixed security mode in this case).

2) Use tracing to determing actual WCF error on your server. Or change

<serviceDebug includeExceptionDetailInFaults="false" />

to

<serviceDebug includeExceptionDetailInFaults="true" />

while you are debugging your app.

Community
  • 1
  • 1
Ivan Samygin
  • 4,210
  • 1
  • 20
  • 33