Link to home
Start Free TrialLog in
Avatar of RTSol
RTSol

asked on

WCF service on local IIS not working

Hi,

I have made a WCF service which I consume in an WPF application. I all works fine when I run the service in the VS development server but when I install it in the local IIS I run into problems - se the attached screen dump. Sorry about the Swedish but it says something like this:

The server was unable to process the request due to an internal error. For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.

If I go to http://localhost/Service1.svc in a web browser it looks fine.

Can you help with this?

Best regards
RTSOL
WCFError.png
Avatar of RTSol
RTSol

ASKER

Hi again,

I should add that I am using VS 2012 and Windows 10.

-RTSOL
Avatar of Systech Admin
it seems that exceptions are not enable. please refer below link which might help you to understand the isseu

http://social.technet.microsoft.com/wiki/contents/articles/17418.the-famous-system-servicemodel-faultexception1-was-unhandled-by-user-code.aspx
Avatar of RTSol

ASKER

Hi,

I have tested some more and it seems that methods that involve calls to an SQL server is the ones that doesn't work. Is there a cross domain problem maybe. As I said earlier it works fine with the development server but not in my local ISS. Here is my service:

using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Web.Security;

namespace WcfTest
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select Service1.svc or Service1.svc.cs at the Solution Explorer and start debugging.
    public class Service1 : IService1
    {
        public string SDConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["dbSmartDocConnectionString"].ConnectionString;
        public string sql = string.Empty;

        public string getCountry() //Works fine in the development server but not in ISS
        {
            string name = string.Empty;
            using (SqlConnection spConn = new SqlConnection())
            {
                sql = "SELECT TOP 1 Land FROM Countries";
                spConn.ConnectionString = SDConnectionString;
                SqlCommand cmd = new SqlCommand(sql, spConn);
                spConn.Open();
                SqlDataReader rdr = cmd.ExecuteReader();
                while (rdr.Read())
                {
                    name = rdr[0].ToString();
                }
            }
            return name;
        }

        public Boolean Login(string usr, string psw) //Works fine in the development server but not in ISS
        {
            Boolean ok = false;
            if (Membership.ValidateUser(usr, psw))
            {
                ok = true;
            }
            return ok;
        }

        public string GetData(int value) //Works fine in the development server as well as in ISS
        {
            return string.Format("You entered: {0}", value);
        }

    }
}

Open in new window

Hope you can help!

-RTSOL
Avatar of RTSol

ASKER

Hi,

I have now installed the service on a remote server (2008 R2) and there it works fine from mu WPF app.

So, it works on my development server, on the remote server but not on my local IIS.

Can someone please help me?

Best regards
Robert Tell
ASKER CERTIFIED SOLUTION
Avatar of Mlanda T
Mlanda T
Flag of South Africa image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RTSol

ASKER

Hi,

Thanks for the input. I caught the error in the service and wrote the error message to a text file. It says:

Cannot open database "dbSmartDocBoSmart" requested by the login. The login failed.
Login failed for user 'NT instans\SYSTEM'.

So I changed to sql login and it works. This raises this question:

In my production server I use windows login and it works provided I set the identity in the application pool to LocalSystem. So - why doesn't this work in my local IIS. I did set the the identity in the application pool to LocalSystem also here?

Can you please comment on this and I will close the question.

Best regards
Robert Tell
LocalSystem in either case refers to the local machine itself. This is technically a different account between your computer and the server.

Also, ( https://msdn.microsoft.com/en-us/library/ms677973(v=vs.85).aspx ):
When a service runs under the LocalSystem account on a computer that is a domain member, the service has whatever network access is granted to the computer account, or to any groups of which the computer account is a member.
 Your laptop and the server probably have different permissions in the AD. So one might allow access to the database, whilst the others might not.