Tuesday, June 19, 2012

Error Type: "could not find default endpoint element that references contract 'ServiceReference1.IService1' in the ServiceModel client configuration section"


I have created WCF Service and trying to consume it in a Sharepoint web part. It is giving following error while deploying web part :
"could not find default endpoint element that references contract 'ServiceReference1.IService1' in the ServiceModel client configuration section".

Here my solution ....

need to create endpointaddress and BasicHttpBinding instance and need to pass these two instance to ServiceClient clasee as parameters.

here is my code..

private static string websiteUrl = "http://demoshare:6969";
BasicHttpBinding binding = new BasicHttpBinding();
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly;
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm;
EndpointAddress endpoint =new EndpointAddress(websiteUrl + "/_vti_bin/udaywcf/ukreddywcf.svc");
ConsumeUKReddyWCF.UdayWcfService.Service1Client proxy = new ConsumeUKReddyWCF.UdayWcfService.Service1Client(binding, endpoint);
proxy.ClientCredentials.Windows.AllowedImpersonationLevel =
                System.Security.Principal.TokenImpersonationLevel.Impersonation;
            string str = proxy.GetSiteName();

            if (txtNumber.Text.Trim() != "")
                str += " and " + proxy.GetData(Convert.ToInt32(txtNumber.Text));
            lblMsg.Text = str;

1 comment: