locked
Getting Error while accessing Discovery service through C# code RRS feed

  • Question

  • Following is error

    The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: '

    In 2011 same code was working fine, now when I am using same code in 2015 its throwing this error.

    I am not using any sdk reference, just service reference and  following code.

    private DiscoveryService.DiscoveryServiceClient GetDiscoveryClient()
            {
    
                // Create an empty CustomBinding to populate
                CustomBinding binding = new CustomBinding();
                // Create a SymmetricSecurityBindingElement.
                SymmetricSecurityBindingElement ssbe =
                    SecurityBindingElement.CreateSspiNegotiationBindingElement(true);
                ssbe.DefaultAlgorithmSuite = System.ServiceModel.Security.SecurityAlgorithmSuite.Default;
                ssbe.IncludeTimestamp = true;
                ssbe.MessageSecurityVersion = System.ServiceModel.MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10;//"WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10";
                ssbe.RequireSignatureConfirmation = false;
                ssbe.SetKeyDerivation(true);
                ssbe.LocalClientSettings.DetectReplays = true;
                ssbe.LocalServiceSettings.DetectReplays = true;
                // Add the SymmetricSecurityBindingElement to the BindingElementCollection.
                binding.Elements.Add(ssbe);
                var bindingElement = new TextMessageEncodingBindingElement();
                bindingElement.MaxReadPoolSize = 200 * 1400;
                bindingElement.MaxWritePoolSize = 200 * 1400;
                bindingElement.ReaderQuotas.MaxArrayLength = 200 * 1400;
                bindingElement.ReaderQuotas.MaxBytesPerRead = 200 * 1400;
                bindingElement.ReaderQuotas.MaxDepth = 1000;
                bindingElement.ReaderQuotas.MaxStringContentLength = 200 * 1400;
                binding.Elements.Add(bindingElement);
                var httpTransportElement = new HttpTransportBindingElement();
                httpTransportElement.MaxBufferPoolSize = 200 * 1400;
                httpTransportElement.MaxBufferSize = 200 * 1400;
                httpTransportElement.MaxReceivedMessageSize = 200 * 1400;
                binding.Elements.Add(httpTransportElement);
    
                //EndpointIdentity eidentit = EndpointIdentity.CreateUpnIdentity("CRMAPPSVC@DC05.loc");
    
    
    
                //AddressHeader[] addressHeaders = new AddressHeader[1];
    
                //EndpointAddress10 fromEndPoint = EndpointAddress10.FromEndpointAddress(new EndpointAddress("url"));
    
                //addressHeaders[0] = AddressHeader.CreateAddressHeader("From", "http://www.w3.org/2005/08/addressing", fromEndPoint);
    
    
                //AddressHeaderCollection addressHeadersc = new AddressHeaderCollection(addressHeaders);
    
    
                DiscoveryService.DiscoveryServiceClient client = new DiscoveryService.DiscoveryServiceClient(binding, new EndpointAddress(new Uri("https://*******.api.crm5.dynamics.com/XRMServices/2011/Organization.svc")));//, eidentit, addressHeadersc));
    
                return client;
    
            }

     private void button1_Click(object sender, EventArgs e)
            {
    
        
                DiscoveryService.DiscoveryServiceClient client = GetDiscoveryClient();
                client.ClientCredentials.Windows.ClientCredential.Domain = "";
                client.ClientCredentials.Windows.ClientCredential.UserName = "username";
                client.ClientCredentials.Windows.ClientCredential.Password = "password";
    
                RetrieveOrganizationsRequest orgsRequest =
                            new RetrieveOrganizationsRequest()
                            {
                                AccessType = DiscoveryService.EndpointAccessType.Default,
                                Release = OrganizationRelease.Current
                            };
                RetrieveOrganizationsResponse organizations =
                    (RetrieveOrganizationsResponse)client.Execute(orgsRequest);
    
    
                foreach (DiscoveryService.OrganizationDetail res in organizations.Details)
                {
                    listBox1.Items.Add(res.UniqueName);
                }
            }

    Following is the error screenshot


    Thanks Regards Prashanth Kamasamudram Even the least work done for others awakens the power within; even thinking the least good of others gradually instills into the heart the strength of a lion.


    Wednesday, December 16, 2015 6:05 AM

All replies

  • Looks like you're getting an html response, which indicates either a server error, or an incorrect url. What happens if your browse to the url you're using ?

    Microsoft CRM MVP - http://mscrmuk.blogspot.com/ http://www.excitation.co.uk

    Wednesday, December 16, 2015 2:17 PM
    Moderator
  •    Url is working fine, problem is only when I am trying access service service from code, first thing is its saying the protocol https:// is not supported and should use http://

    so I changed my url to http://xxx.xxx.xxx  , then after this I am getting following error.

    "The content type text/html; charset=utf-8 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 1024 bytes of the response were: "


    Thanks Regards Prashanth Kamasamudram Even the least work done for others awakens the power within; even thinking the least good of others gradually instills into the heart the strength of a lion.


    Thursday, December 17, 2015 5:13 AM