web service - web-services

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.

Related

MSCRM 2013 - The caller was not authenticated by the service

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.

SoapUI basic authentication to c# code

I have problem with web service I want to connect to.
In soapUI i used basic authentication with username and password (domain empty), and changed WSS-Password Type to PasswordText and I could without a problem connect to web service. But when I try to connect using c# code:
WebService service = new WebService();
service.ClientCredentials.UserName.UserName = "user";
service.ClientCredentials.UserName.Password = "pass";
service.SomeMethod();
It returns "Forbidden" error.

SOAP Exception when trying to Access GP WebServices

I am trying to write a program that simply connects up to a GP WebService and invokes it's GetCustomerList() method to get customers from Great Plains. The code I am outlining below is an duplication of what I was able to find in the documentation, however, when I run it I am getting a SoapException. I am not sure if I am missing credentials (eg. username and password) or if I am even invoking this properly. I believe that I have the Security settings set correctly in the Dynamics Security Console, but I am not 100% sure or if there is anything else I need to configure. Any help would be greatly appreciated.
public IList<string> GetCustomerNames()
{
//Added a ServiceReference to the actual WebService which appears to be working
var service = new DynamicsGPClient();
var context = new Context();
var customerKey = new CustomerKey();
var companyKey = new CompanyKey();
//Trying to load the test data
companyKey.Id = (-1);
context.OrganizationKey = (OrganizationKey)companyKey;
//Trying to load the test data
customerKey.Id = "AARONFIT0001";
var customers = service.GetCustomerList(new CustomerCriteria(), context);
return customers.Select(x => x.Name).ToList();
}
Sounds like a security issue ... are you getting a specific error message ... that might be helpful ...
Also found this ...
It sounds to me like you need a Windows App Pool Identity on your
webservice. Right now you have the IIS Security set to "anonymous", so the
clients aren't required to pass the credentials when they call your methods.
You'll need to turn that off and run your app pool as a windows account. Once
you've got that working, you can choose if you want to just add that one App
Pool identity into the security for webservices, and have all the operations
done as that account (poor security), or, in your wrapper, you could use the
HTTP User's context identity, and set it to the "WorkOnBehalfOf" property for
the GP WebService call you're actually using.
You'll have to give the App
Pool identity "WorkOnBehalfOf" permission in the web service security
console, and then whichever users you want to call the webservice. This keeps
the security model intact, and you're authorizing that the users calling the
wrapped webservice actually do have permission to call the original GP
Webservice methods. (This is how Business Portal forwards requests to the
webservices.)
https://groups.google.com/forum/?fromgroups=#!topic/microsoft.public.greatplains/W7gAo_zXit8

Consuming Web Service via Windows Authentication

I am just trying to consuming a web service in remote computer using windows authentication however login credentials are different in local & remote computer.
Code Snippet:
Dim objproxy As New WebReference.Service1
'Create a new instance of CredentialCache.
Dim mycredentialCache As CredentialCache = New CredentialCache()
'Create a new instance of NetworkCredential using the client
Dim credentials As NetworkCredential = New NetworkCredential("username", "pwd","domain")
'Add the NetworkCredential to the CredentialCache.
'mycredentialCache.Add(New Uri(objproxy.Url), "Basic", credentials)
objproxy.Credentials = credentials
It is timing out but when i use
mycredentialCache.Add(New Uri(objproxy.Url), "Basic", credentials)
I get "401 Unauthorized" message,
Please assist.
You want windows authentication so use:
mycredentialCache.Add(New Uri(objproxy.Url), "Negotiate", credentials)
See Passing Credentials for Authentication to Web Services

Authorize proxy access in code if customer is using Microsoft ISA Server

my code is providing an access to our web service.
WebProxy proxy = new WebProxy(ProxyURL, ProxyPort);
proxy.UseDefaultCredentials = false;
NetworkCredential nc = new NetworkCredential( ProxyLogin, ProxyPassword);
proxy.Credentials = nc;
myWebService.Proxy = proxy;
My problem is that customer doesn't know ProxyLogin and ProxyPassword, especially if he is running Microsoft ISA server. Company policy doesn't allow him to know password and login.
Is there anyway to reach authorization information by code?
There is no way to get password by code. If there was a way it would be a security vulnerability.
The user should have proxy access for his account. If he don't have, Than this is the end of it. If he has proxy access than your application should use his credentials.
proxy.UseDefaultCredentials = true;