MSCRM 2013 - The caller was not authenticated by the service - web-services

I am trying to call CRM webservice from my custom WCF service. And I am getting the exception "The caller was not authenticated by the service". Checked the authentication mode in IIS (where my wcf service is hosted). Its set to anonymous authentication enabled.
Is there any reason why MSCRM service would fail authentication while call is made from WCF?
Here is my code which calls the CRM web service
OrganizationService service;
var crmConnection = CrmConnection.Parse("Server=http://myserver/orgname; Domain=domainname; Username=username; Password=passwordtext");
service = new OrganizationService(crmConnection);
Entity crmEvent = service.Retrieve("new_event", eventId, new ColumnSet("status"));

When using windows authentication you need to pass a Networkcredential to the constructor of the OrganizationService.
This was already answered by #Daryl here.

Related

How to authenticate with Dynamics Nav web service from LotusScript

Running Lotus Notes Domino 8.5.2. I have created a LotusScript web service consumer from a wsdl provided by a Microsoff Dynamics Nav server.
In a LotusScript agent I have this code
Dim nav As New Noteswebservice_port_n2()
Call nav.Setcredentials("DOMAIN\username", "password")
Dim res As String
res = nav.Createorder("123", "", "test", "CH")
The problem is that I get 401 Unauthorized, when calling CreateOrder.
I have tested the web service from Visual Studio, and it works with the same credentials as used in the agent.
I suspect that Lotus Domino and Dynamics doesn't use the same authentication method. I have tried to enable NTLM on Dynamics, but same result. I have no idea what to do next.
Any ideas?
Microsoft is using WS-Security in most Web Services by default. I don't know how it is with Dynamics Nav, but I assume it.
Complete description how to use with IBM Notes from Java:
Extending IBM Domino Web Service Consumers to support SOAP Authentication (Java)

passing user credentials to web service

I have the following scenario:
I have an application (html files + javascripts hosted in a webserver)
There is a SOAP web service that we need to develop.
Web service will be called from java script (AJAX calls).
User will access the application in intranet scenario. Users are validated against active drectory.
Requirement states that user need to be logging in using logged in users network credentials. There should not be a login screen shown to user.
Web service interfaces need to be invoked with logged in users credentials. A login inteface of web service specifically needs to be called as first call.
I have a specific question on how to pass user credential to web service.
I am planning to configure Integrated windows authentication (NTLM) for web application to avoid login screen.
However I do not know a way to capture and send user id and password to login interface of web service.
Most of the questions and answers around this topic has been for microsoft technlogies. Any specific ideas?
Further research and several blog posts pointed me to Kerberos authentication and a single sign on framework. With NTLM i cannot delegate credentials to web service. However with Kerberos i can. I will be using SPNEGO and delegate the credentials after authentication. Please refer to below link for further details.
http://spnego.sourceforge.net/

How to call web service that requires claims based authentication?

I have a client that wants to invoke a web service.
I have a web service(asmx) , a default.aspx that can show the claims .
I have a test STS that my web service trusts.
I tested and sts can send correct claims and also web service seems to get them if I go through default.aspx page that shows the claims. I created a proxy(using Visual Studio "add service reference") for client to call the web service. I could not find a way about how to call web service from client programatically so that it will authenticate through my STS. I am calling like below but sts returns the claims response to client where it should return to web service and invoke the web service function.
MyClient = MyWebServiceSoapClient("MyWebServiceSoap", "http://127.0.0.1:81/MyService.asmx?whr=http%3a%2f%2flocalhost%3a25919%2fteststs%2fdefault.aspx%3fwa%3dwsignin1.0%26wtrealm%3dhttp%3a%2f%2f127.0.0.1%3a81%2fmyservice.asmx");
MyClient.MyServiceFunction();
Check samples in the Identity Training Kit or the "A Guide to Claims based Identity" for examples.
I wrote a C# library that enables you to get a SAML token from a 3rd party STS and subsequently ADFS to eventually authenticate to SharePoint. It may be of some help:
http://www.huggill.com/2012/02/04/claims-proxy-a-c-sharp-library-for-calling-claims-protected-web-services/

How do I call a Sharepoint Webservice from a c# client using Kerberos authentication?

We have developed a webservice that sits and runs in the context of a sharepoint site. This works fine using normal windows authentication.
We now have a client who wants to install this on a Kerberos enabled sharepoint site. What changes would we need to make to either the webserivce, the calling client (a windows service) or both to enable this...?
Is this in an intranet?
If so, and your client is already passing windows credentials to the web service, you shouldn't have to do any additional work.
If you aren't passing windows credentials, here is how to do it :
WebServiceProxy proxy = new WebServiceProxy(); // Derived from SoapHttpClientProtocol
proxy.Credentials = CredentialCache.DefaultCredentials;
This method works for both NTLM and Kerberos authentication. It will pass the credentials of the windows account under which the code is running.

web service

I have web service, which use integrated security in IIS.
Now, I want to test my web service.
I created a console application and adding web reference.
now, when i m trying to use web method. It show 401 error.
m i missing any authentication.
I think i need to pass user name and password programatically.
can anyone direct me in right direction.
Set the web service credentials to the System.Net.CredentialCache.DefaultCredentials in your console app
MyWebService proxy = new MyWebService();
proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
Edit
pass credentials programmatically:
MyWebService proxy = new MyWebService();
proxy.Credentials = new System.Net.NetworkCredential("username", "password", "domainname");
You need to add your windows id on your desktop to the allowed users in IIS.