locked
How to configure ServiceClient to Authenticate a Client in C# to consume MDS Web Service? RRS feed

  • Question

  • Hi everyone!

    Well, Im working with a simple web application develeped on Visual Studio using Html, Java script and C# to make the connection with the MDS Web service, but I have a little problem, First, the web application  Im developing on my computer is connecting to a Intranet, and actually I have this code to make the connection using a service client:

    private static string mdsURL = @"http://server.domain.net:8001/service/service.svc";

     private static string user;

    private static ServiceClient CreateMdsProxy(string mdsURL){ user = HttpContext.Current.Request.LogonUserIdentity.Name; EndpointAddress pntFinalAddress = new EndpointAddress(new Uri(mdsURL), EndpointIdentity.CreateUpnIdentity("@domain.com")); WSHttpBinding wsBinding = new WSHttpBinding(SecurityMode.Message); wsBinding.Security.Message.ClientCredentialType = MessageCredentialType.Windows; wsBinding.MaxReceivedMessageSize = 2147483646; wsBinding.MaxBufferPoolSize = 2147483646; return new ServiceClient(wsBinding, pntFinalAddress); }

    And after that, Im using this method to get Service Client and ask to the MDS information.

     public static string GetEntityMember()
            {
                messageReturn = "";
                MemberIdentifier memberIdentifier = new MemberIdentifier();
    
                try
                {
                   
                    mdsProxy = CreateMdsProxy(mdsURL);
                    
                    mdsProxy.ClientCredentials.UserName.UserName = "COMPANY\\Myaccount";
                    mdsProxy.ClientCredentials.UserName.Password = "mypassword";
    
                    
                    // Create the request object to get the entity information.
                    EntityMembersGetRequest getRequest = new EntityMembersGetRequest();
                    getRequest.MembersGetCriteria = new EntityMembersGetCriteria();
    
                    // Set the modelId, versionId, entityId, and the member name.
                    getRequest.MembersGetCriteria.ModelId = new Identifier { Name = "MyModel" };
                    getRequest.MembersGetCriteria.VersionId = new Identifier { Name = "VERSION_1" };
                    getRequest.MembersGetCriteria.EntityId = new Identifier { Name = "MyEntity" };
                    getRequest.MembersGetCriteria.MemberType = MemberType.Leaf;
                    getRequest.MembersGetCriteria.MemberReturnOption = MemberReturnOption.Data;
                    getRequest.MembersGetCriteria.SearchTerm = "country = USA ";
                    getRequest.MembersGetCriteria.SortColumnId = new Identifier { Name = "facility" };
    
                    System.Collections.ObjectModel.Collection<Identifier> AttributesID = new System.Collections.ObjectModel.Collection<Identifier>();
                    AttributesID.Add(new Identifier() { Name = "country" });
                    AttributesID.Add(new Identifier() { Name = "facility" });
                    AttributesID.Add(new Identifier() { Name = "population" });
                    AttributesID.Add(new Identifier() { Name = "genre" });
                    AttributesID.Add(new Identifier() { Name = "age"});
                    getRequest.MembersGetCriteria.Attributes = AttributesID;
    
                    
                    
    
                    EntityMembersGetResponse getResponse = mdsProxy.EntityMembersGet(getRequest);// Get the entity member information
                    messageReturn += ShowAttributeInformation2(getResponse.EntityMembers.Members); 
                }
                catch (Exception ex)
                {            
                    messageReturn += "Fail --- Failed to Get Members ---- : " + ex.Message;
                    messageReturn +=  " Username Detected: " + user;
    
                }
    
                return messageReturn;
            }

    Here is my Web.Config client file:

    <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=169433
      -->
    <configuration>
      <system.web>
        <compilation debug="true" targetFramework="4.5.2" />
        <httpRuntime targetFramework="4.5.2" />
      </system.web>
      <system.serviceModel>
        <bindings>
          <wsHttpBinding>
            <binding name="BasicHttpBinding_IService">
              <security mode="Message">
                <message clientCredentialType="Windows"/>
              </security>
            </binding>
          </wsHttpBinding>
          <wsHttpBinding>
            <binding name="WSHttpBinding_IService">
              <security mode="Message">
                <message clientCredentialType="Windows"/>
              </security>
            </binding>
          </wsHttpBinding>
        </bindings>
        <client>
          <endpoint address="http://server.domain.net:8001/service/service.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService"
            contract="ServiceMDS.IService" name="WSHttpBinding_IService">
            <identity>
              <userPrincipalName value="DSSService@domain.net" />          
            </identity>
          </endpoint>
          <endpoint address="http://server.domain.net:8001/service/service.svc/bhb"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
            contract="ServiceMDS.IService" name="BasicHttpBinding_IService" />
        </client>
      </system.serviceModel>
    </configuration>

    Well, This example works excellent on my computer, and Master Data retrieve me the correct information that I requested.

    But, the problem comes when I publish this example on a server (Server A) who is running IIS to host this web application and this server is not the same one on which the "Master Data Services" is Installed (Server B). Currently, I have enabled the "Windows authentication" on Server A. But I don´t know if I must follow the same procedure  on the Server B, Besides, I don´t have access to that server.

    At the moment I'm very confusing and I will thank you if you can help me with a example o with useful information (with examples preferably). About how I can configure ServiceClient  on my code to this web application works.

    Thank You !
    Regards.

    Tuesday, April 24, 2018 10:28 PM

All replies

  • What error do you get when deployed and run through a server?

    My guess is may be due to incorrect service url and userprincipalname it is not working

    EndpointIdentity.CreateUpnIdentity("@domain.com") should mention the actual userprincipalname for the mds service same as what you see in web.config under endpoint settings.

    Friday, May 4, 2018 12:14 AM