0

I am trying to connect to CRM 2011 on premise from windows azure worker role through WCF web services. I have created a WCF webservice. But while running the application it is showing error as "Inconsistent accessibility: field type SampleData_WcfService.OrganizationServiceProxy' is less accessible than field 'SampleData_WcfService.Service1._SDKObject". I have written the code as

namespace SampleData_WcfService
{
    public class Service1 : IService1
    {
    public static OrganizationServiceProxy _SDKObject;
       public bool CRMCall()
        {
            try
            {
                if (!CRM_Connection("http://orgname/dattgtdev/XRMServices/2011/Organization.svc", "false", "user2", "pwd", "domain"))
                    return false;

                Entity _entity = new Entity();
                _entity.LogicalName = "account";
                _entity.Attributes.Add(new KeyValuePair<string, object>("name", "Testing123456787"));

               _SDKObject.Create(_entity);
                return true;
            }
            catch (Exception ex)
            {
                return false;
                           }
        }

  public bool CRM_Connection(string WebServiceURL, string Authentication, string UserName, string Password,string DomainName)
        {
            try
            {
                Uri organizationUri = new Uri(WebServiceURL);
                Uri homeRealmUri = null;
               System.ServiceModel.Description.ClientCredentials credentials = new System.ServiceModel.Description.ClientCredentials();
                if (Authentication == "false")
                {
                    credentials.Windows.ClientCredential = new System.Net.NetworkCredential(UserName, Password, DomainName);
                }

                _SDKObject = new OrganizationServiceProxy(organizationUri, homeRealmUri, credentials, null);

                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
 }

Whats wrong with this code??

Raphaël Althaus
  • 57,325
  • 6
  • 81
  • 109
rubyist
  • 2,918
  • 7
  • 33
  • 59
  • That's odd. `OrganizationServiceProxy` class is supposed to be `public`. How are you referencing CRM's types, is it SDK or a definition created by `CrmSvcUtil` ? – Alex Jul 26 '12 at 14:39
  • It is referincing through sdk – rubyist Jul 26 '12 at 14:44
  • I tried your code on my machine on one of our CRM development environments and it works just fine so I'd say your code is ultimately correct. It has to be Azure's fault somehow but unfortunately I don't have any means of testing it. I'd try to ask on Microsoft forums. – Alex Jul 26 '12 at 14:50

1 Answers1

4

_SDKObject is public, while the OrganizationServiceProxy class will most probably be internal. Make the class accesor public, or make the _SDKObject declaration less accesible, like internal, protected or private.

CodeCaster
  • 131,656
  • 19
  • 190
  • 236
  • I'm sorry to say it, but this answer doesn't really make much sense since OrganizationServiceProxy is defined as public and part of the platform itself... – Alex Jul 26 '12 at 14:48
  • @Alex that might be true, but then the compiler wouldn't throw this error. – CodeCaster Jul 26 '12 at 14:50
  • I tried making _SDKObject as internal. And now it is showing error as "SampleData_WcfService.OrganizationServiceProxy' does not contain a constructor that takes 4 arguments".. But I am wondering that I am passing those 4 arguments and why OrganizationServiceproxy is not accepting it and throwing an error – rubyist Jul 26 '12 at 15:07
  • @user662503 `SampleData_WcfService.OrganizationServiceProxy` ... so you have a class called `OrganizationServiceProxy` in your namespace (perhaps a too eager `Ctrl+.`, `Enter` which created the class in your namespace?). Use `Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy`. – CodeCaster Jul 26 '12 at 15:10
  • Sorry.. I didn't get what you mean by that?? I am new to Dot net and just started learning – rubyist Jul 26 '12 at 15:27
  • I tried Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy. But it is showing "A using namespace directive can only be applied to namespaces; 'Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy' is a type not a namespace" – rubyist Jul 26 '12 at 15:29
  • 1
    @user662503 the exception states that the `OrganizationServiceProxy` class comes from the `SampleData_WcfService` namespace, which is **your** namespace. So you will have to have created such a class, which does not contain a constructor that takes four arguments. Remove the class and add a `using Microsoft.Xrm.Sdk.Client` statement, or change the `_SDKObject` declaration to `public static Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy _SDKObject;`. Please learn to read exception messages, since they're usually really clear about what is going wrong. – CodeCaster Jul 26 '12 at 15:29
  • As you said I have declared it as public static Microsoft.Xrm.Sdk.Client.OrganizationServiceProxy _SDKObject; and I have also included the Microsoft.Xrm.Sdk.Client. But it is still showing error as "SampleData_WcfService.OrganizationServiceProxy' does not contain a constructor that takes 4 arguments – rubyist Jul 26 '12 at 15:47
  • 1
    @user662503 that is because you're still calling the constructor of your own class. Take a look in your solution and remove the OrganizationServiceProxy class. – CodeCaster Jul 26 '12 at 15:55