locked
Error: The caller was not authenticated by the service. RRS feed

  • Question

  • Hi,

    I am starting learning wcf. I look at a wcf sample(Getting started tutorial) at a microsoft web site (http://msdn.microsoft.com/en-us/library/ms731835.aspx).

    When I run a client program, I got an error: "The caller was not authenticated by the service."

    I copied the client code here.

    using System;
    using System.Configuration;
    using System.ServiceModel;
    using System.ServiceModel.Channels;
    using System.ServiceModel.Description;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Client.ServiceReference1;

    namespace Client
    {
        class Program
        {
            static void Main(string[] args)
            {
                //Step 1: Create an endpoint address and an instance of the WCF Client.

                CalculatorClient client = new CalculatorClient();


                // Step 2: Call the service operations.
                // Call the Add service operation.
                double value1 = 100.00D;
                double value2 = 15.99D;
                double result = client.Add(value1, value2);//The caller was not authenticated by the service.
                Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);

                // Call the Subtract service operation.
                value1 = 145.00D;
                value2 = 76.54D;
                result = client.Subtract(value1, value2);
                Console.WriteLine("Subtract({0},{1}) = {2}", value1, value2, result);

                // Call the Multiply service operation.
                value1 = 9.00D;
                value2 = 81.25D;
                result = client.Multiply(value1, value2);
                Console.WriteLine("Multiply({0},{1}) = {2}", value1, value2, result);

                // Call the Divide service operation.
                value1 = 22.00D;
                value2 = 7.00D;
                result = client.Divide(value1, value2);
                Console.WriteLine("Divide({0},{1}) = {2}", value1, value2, result);

                //Step 3: Closing the client gracefully closes the connection and cleans up resources.
                client.Close();


                Console.WriteLine();
                Console.WriteLine("Press <ENTER> to terminate client.");
                Console.ReadLine();


            }
        }
    }

    Thanks for any idea.

     

    Best regards

     

    Wednesday, September 29, 2010 6:17 AM

Answers

All replies

  • I think you are using the wsHttpBinding? This binding uses Message security with windows auth by default. I'll suggest that since you just want to learn to use WCF - you can change the binding to basicHttpBinding which does not use any security and should avoid the error you are seeing. If you want to stick with wsHttpBinding, either you can turn off security on this binding or make sure that the client and service can confirm a valid windows identity (is this a domain joined machine you are working?) You can also try regenerating the client which I believe should contain the security information (SPN/UPN) to talk correctly to the service if the client and service can confirm a valid windows identity.

     


    - Piyush
    Wednesday, September 29, 2010 6:47 AM
  • Is this happening on a single machine or are you using two machines for testing this?
    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    Twitter: richardblewett
    Wednesday, September 29, 2010 9:10 AM
  • Hi Piyush,

    Thanks for your help.

    If you want to stick with wsHttpBinding, either you can turn off security on this binding or make sure that the client and service can confirm a valid windows identity (is this a domain joined machine you are working?)

    I am learning WCF. but I will build my application based on it. So I like to use wsHttpBinding. My PC is on the domain. How can I make the client and service confirm a valid windows identity?

    You can also try regenerating the client which I believe should contain the security information (SPN/UPN) to talk correctly to the service if the client and service can confirm a valid windows identity.

    How to do that?

     

    Best regards

     

    stephen

    Thursday, September 30, 2010 12:37 AM
  • Hi Richard,

    Thanks for help.

    This happened in the same PC.

     

    Best regards

    Stephen

     

    Thursday, September 30, 2010 12:39 AM
  • http://msdn.microsoft.com/en-us/library/ms733133.aspx describes in the tutorial how you can generate the client proxy. You can also try providing explicit credentials on the client side -

    proxy.ClientCredentials.Windows.ClientCredential.UserName = "name";

    proxy.ClientCredentials.Windows.ClientCredential.Password = "pwd";


    - Piyush
    • Marked as answer by Bin-ze Zhao Monday, October 4, 2010 8:06 AM
    Thursday, September 30, 2010 8:46 AM
  • If you are running on the same PC then its unlikely to be a windows credenial problem unless you are using domain accounts and the DC is not available. Can you turn on tracing in the service and see of the security infrastructure is getting upset? I have recorded a screencast that shows you how here

    http://rocksolidknowledge.com/ScreenCasts.mvc/Watch?video=WCFTracing.wmv


    Richard Blewett, thinktecture - http://www.dotnetconsult.co.uk/weblog2
    Twitter: richardblewett
    • Marked as answer by Bin-ze Zhao Monday, October 4, 2010 8:06 AM
    Thursday, September 30, 2010 9:14 AM