locked
C# client application throwing authentication failure error while connecting to MDS (2012) RRS feed

  • Question

  • Hi,

    I'm trying to write a sample client-side C# code that will connect to MDS and create an entity there. I'm using the sample codeplex code and made necessary changes to the mds service url. Here is my code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.ServiceModel;
    using CreateEntity.MDS2012Service;

    namespace CreateEntity
    {
        class Program
        {

            private static ServiceClient clientProxy;
            // Set the MDS URL (plus /Service/Service.svc) here.
            private static string mdsURL = @"http://<My Server Name>/MDS2012/Service/Service.svc";

            static void Main(string[] args)
            {
                try
                {
                    clientProxy = GetClientProxy(mdsURL);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error creating a service proxy: {0}", ex);
                    return;
                }

            }
            // Creates MDS service client proxy.
            private static ServiceClient GetClientProxy(string targetURL)
            {
                // Create an endpoint address using the URL.
                      
                EndpointAddress endptAddress = new EndpointAddress(targetURL);
                // Create and configure the WS Http binding.
                WSHttpBinding wsBinding = new WSHttpBinding();

                // Create and return the client proxy.
                return new ServiceClient(wsBinding, endptAddress);
            }
       }
    }

    When I execute this code, it throws an authentication error as follows:

    If the server is running in a servce account (Network Service for example), specify the account's ServicePrincipalName as the identity in the EndpointAddress for the server. If the server is runing in a user account, specify the account's UserPrincipalName as the identity in the EndpointAddress for the server.

    Now, when I look at the app.config, I do find a section containing the UserPrincipalName as follows:

            <client>
                <endpoint address="http://<My server name>/MDS2012/Service/Service.svc"
                    binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService"
                    contract="MDS2012Service.IService" name="WSHttpBinding_IService">
                    <identity>
                        <userPrincipalName value="me@domain.com" />
                    </identity>
                </endpoint>
              <endpoint address="http://<My server name>/MDS2012/Service/Service.svc/bhb"
                  binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
                  contract="MDS2012Service.IService" name="BasicHttpBinding_IService" />         
            </client>

    Why then is it throwing the authentication error? I'm able to access "http://<My server name>/MDS2012/Service/Service.svc" otherwise. Although I'm quite familiar with MDS, I'm completely new to C#. Is there something that I'm missing? Do I need to make any modifications to ensure that the app.config file is getting referred?


    Wednesday, July 18, 2012 2:30 PM

Answers

  • Ok - I have been able to resolve this - I used a different overload of EndpointAddress with arguments EndpointAddress(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers) and now it works from the client side as well. Now, I should tweak this further to pick up the logged in user name instead of the hardcoded name.
    • Marked as answer by MSBI Dev 2012 Thursday, July 19, 2012 5:08 AM
    Thursday, July 19, 2012 5:08 AM

All replies

  • An additional note: When I copied the C# exe to the server machine and executed it there, it ran successfully. What changes should I make to the code so that I can run it from the client machines?

    Thursday, July 19, 2012 4:07 AM
  • Ok - I have been able to resolve this - I used a different overload of EndpointAddress with arguments EndpointAddress(Uri uri, EndpointIdentity identity, AddressHeaderCollection headers) and now it works from the client side as well. Now, I should tweak this further to pick up the logged in user name instead of the hardcoded name.
    • Marked as answer by MSBI Dev 2012 Thursday, July 19, 2012 5:08 AM
    Thursday, July 19, 2012 5:08 AM