PSI authentication only returns 401 - web-services

I'm developing a web-service that is going to be a "gatekeeper" between many apps and the PSI. the thing is that the "many apps" will supply a login/password and the web-service must authenticate them against the PSI. But whatever i do i always get a 401 Unauthorized error when i call the "PSIFormsLogin.Login(user,password)" method... ive used even the user that runs the farm...
ive also already followed the following MS tutorial: http://msdn.microsoft.com/en-us/library/ff181538.aspx
in the end all i wanna do is validate the account/password supplyed using the PSI web-Services, can anyone pls tell me what am i doing wrong???
PS: not the WCF
New Info: something funny happened. I intentionally switched the URL to a non-existent on: http://myserver/pwa/_vti_bin/psi/bla.asmx but i still got a 401...

Make sure you have modified the web.config of your application like this. Just overwrite the security node in the binding node:
<binding name="WssInteropSoap">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
Now you can authenticate without a special account (passtrough from windows) or with this code, you can specify an account:
//credential impersonation (just if you changed your binding settings)
projectSvc.ClientCredentials.Windows.ClientCredential = new NetworkCredential("username", "password", "domain");
projectSvc.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
I hope it will help :)
But, I've never heard of a function which is called: "PSIFormsLogin.Login"
Maybe my blog entry for setting up a connection to the PSI with C# is interesting for you: Read Project Server 2010 CustomFields over PSI

Related

Web service calling user is always anonymous

I have a simple web service written using WCF. I'm trying to get the details of the caller so I can check their details. I'm doing it like this:
var ident = ServiceSecurityContext.Current.PrimaryIdentity;
However, it's coming back as empty and
bool isAnon = ServiceSecurityContext.Current.IsAnonymous;
is returning true.
How do I get the details? I thought if, in the client I added this to the config:
<security mode="Transport">
<transport clientCredentialType="Windows" />
</security>
to my basicHttpBinding it would do this.
What am I missing? I've been struggling trying to do any kind of authorisation working. This programmatic approach was because I simply failed to get WIA working through IIS.
I tried Current.WindowsIdentity and that was blank too.

Unable to access webservice from Azure WebSite

I have an website hosted in Azure Websites. I am trying to connect to an external webservice, and am getting the message:
There was no endpoint listening at https://myexternalservice.com/ws/
I am able to run this locally, and connect no problem, but having an issue only Azure.
My current binding is a basicHttpBinding defined as such
<bindings>
<basicHttpBinding>
<binding name="myBinding" maxReceivedMessageSize="20000000" maxBufferSize="20000000" maxBufferPoolSize="20000000" openTimeout="00:10:00"
closeTimeout="00:10:00"
sendTimeout="00:10:00"
receiveTimeout="00:10:00">
<readerQuotas maxDepth="32" maxArrayLength="200000000" maxStringContentLength="200000000" />
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://myexternalservice.com/ws" binding="basicHttpBinding" behaviorConfiguration="" bindingConfiguration="myBinding" contract="MyContract" name="MyEndpointName" />
</client>
I'm going to presume this is some sort of internal load balancing that is preventing me from accessing this external address??
Hope someone can help
EDIT
OK, I've tried going onto the Debug console (i.e. mysite.scm.azurewebsites.net) and opening a CMD window. I've tried the following:
nslookup myexternalservice.com
and getting the following:
Server: UnKnown
Address: 10.20.201.9
For mine, this looks to be completely an Azure issue. Anyone else come across a similar type problem?
In the meantime I've reluctantly updated by endpoint address to be bound directly to the IP address, and this has worked, but is not a viable solution going forward. Any help would be appreciated.

Calling a soap web service from Microsoft CRM plugin

I have a plugin which calls a soap based web service on creation of a new contact.Its a simple soap web service which displays a welcome message when called
Below is app.config which contains all configuration requirements.
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="WelcomeBinding" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
<message clientCredentialType="UserName" algorithmSuite="Default"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://revesinc.com/WelcomeSeamService/Welcome" binding="basicHttpBinding" bindingConfiguration="WelcomeBinding" contract="ServiceReference1.Welcome" name="WelcomePort"/>
</client>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>
and below is C# plugin code
BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.Name = "WelcomeBinding";
myBinding.Security.Mode = BasicHttpSecurityMode.None;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
EndpointAddress endPointAddress = new EndpointAddress("http://revesinc.com/WelcomeSeamService/Welcome");
WelcomeClient client = new WelcomeClient(myBinding,endPointAddress);
when i create a contact in CRM, nothing gets displayed on my server. there is no exception on CRM side either.
Any idea???
thanks
At first I want to ask you how are you going to display something on your server? I don't see any way to do this using plugin, but might be I'm not right. In any case, please, show part of code where you are displaying something.
You are saying that nothing happen. At first you should check that the plugin is registered properly. As I understood, you should check that there was added step with entity Contact and Message Create. Also usually plugins are created using some templates. Might be some error is in the part of your code, before calling Web Service.
And another issue I want to emphasize. You have a config file with the configurations of your assembly. I think that for plugin assemblies is better to do not store any configurations in config files, but do all the settings in code.
There are few different ways to check that plugin was fired. At first you can deploy not only dll but also pdb files and attach to the IIS process with the debugger. If there is no Visual Studio installed, you can use Remote Debugger. If it's not possible due some reason, you can throw PluginExecutionException at the beginning of your code to be sure that plug in is really called. And when you will be sure that plug in is working, you can start test working with Web Service.
I assume that you are calling some method which shows the welcome message after this line:
WelcomeClient client = new WelcomeClient(myBinding,endPointAddress);
I would suggest that you should use the tracing service for logging in your plugin. Put your plugin code in try catch and throw InvalidPluginExecutionException after tracing.
Your code may look something like this in the plugin Execute method:
try
{
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.Name = "WelcomeBinding";
myBinding.Security.Mode = BasicHttpSecurityMode.None;
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
EndpointAddress endPointAddress = new EndpointAddress("http://revesinc.com/WelcomeSeamService/Welcome");
WelcomeClient client = new WelcomeClient(myBinding, endPointAddress);
client.ShowWelcomeMessage(); // Assuming this is your service method
tracingService.Trace("All went well. service called.");
throw new InvalidPluginExecutionException("All went well. Exception just to show the traces on the form");
}
catch (Exception ex)
{
tracingService.Trace("Error calling welcome service " + ex.Message);
throw new InvalidPluginExecutionException(ex.Message);
}
If your plugin is registered properly , you will be able to see the exception on the user action (create, update etc). You will know from traces if the service called succesfully or not.

The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM'

I am trying to program a VisualWebPart using Visual Studio 2010 which has to do a simple thing: invoke a web service (hosted in a remote server, NOT locally). When I execute within the Sharepoint site (version 2010, which I have published in my IIS) I get this error:
"The HTTP request is unauthorized with client authentication scheme 'Ntlm'. The authentication header received from the server was 'NTLM'."
Pardon my ignorance, but the only difference here is the case of the Ntlm authentication scheme! I have been all over the web and found many related problems, but none of the solutions worked. Almost ALL solutions i found involve modifications in the webservice security configuration, this is not an option for me.
Looking for a solution, I created a sample windows form and invoked the web service from it: no problems whatsoever.
In order to be able to invoke the webservice correctly this is the necessary security configuration:
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
I believe the problem is that I havenĀ“t been able to properly set this security property to the web.config of my Sharepoint site, since I tried to put it in the security tag that appears in the web.config but still get the same error.
Any further information needed please ask, I am REALLY desperate, for days I have been with the SAME error.
In the end I was given permissions in their server: more precisely in the database which was the one that wouldn't let me create the web part in the server. Once this was done, the call to the webservice worked just fine, because they have the web.config correctly configured.

Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.`

EDIT:
After I modified the web.config and I don't get error that's good.... then I add a new page (html) and write this small code to consume the service like this:
$("#btn12").click(function (event) {
$.getJSON('http://localhost:3576/MyService.svc/GetCurrentUser', {},
function (data) {
alert(data);
});
//return false;
});
I see the following error in my FireBug:
http://localhost:3576/MyService.svc/GetCurrentUser
400 Bad Request
Note: I have added html page on the same wcf project and running the project it self so I am assuming the service is also running ...
What might be wrong here?
END EDIT
I have just created a new wcf services and when I hit f5 from VS and I get this error in WCF Test Client window :
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
Error: Cannot obtain Metadata from http://localhost:3696/MobileService.svc If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.
WS-Metadata Exchange Error
URI: http://localhost:3696/MyService.svc
Metadata contains a reference that cannot be resolved: 'http://localhost:3696/MyService.svc'.
There was no endpoint listening at http://localhost:3696/MyService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
Unable to connect to the remote server
No connection could be made because the target machine actively refused it 127.0.0.1:3696
HTTP GET Error
URI: http://localhost:3696/MyService.svc
There was an error downloading 'http://localhost:3696/MyService.svc'.
Unable to connect to the remote server
No connection could be made because the target machine actively refused it 127.0.0.1:3696
My config:
<behaviors>
<endpointBehaviors>
<behavior name="MyService.MyService">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost:2812/MyService.svc" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="MyService.MyService"
behaviorConfiguration="metadataBehavior">
<endpoint
address="http://localhost/MyService.svc"
binding="customBinding"
bindingConfiguration="jsonpBinding"
behaviorConfiguration="MyService.MyService"
contract="MyService.IMyService"/>
</service>
</services>
<bindings>
<customBinding>
<binding name="jsonpBinding">
<jsonpMessageEncoding/>
<httpTransport manualAddressing="true"/>
</binding>
</customBinding>
</bindings>
<extensions>
<bindingElementExtensions>
<add name="jsonpMessageEncoding" type="Microsoft.Ajax.Samples.JsonpBindingExtension, MyService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</bindingElementExtensions>
</extensions>
You need to add a metadata exchange (mex) endpoint to your service:
<services>
<service name="MyService.MyService" behaviorConfiguration="metadataBehavior">
<endpoint
address="http://localhost/MyService.svc"
binding="customBinding" bindingConfiguration="jsonpBinding"
behaviorConfiguration="MyService.MyService"
contract="MyService.IMyService"/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
Now, you should be able to get metadata for your service
Update: ok, so you're just launching this from Visual Studio - in that case, it will be hosted in Cassini, the built-in web server. That beast however only supports HTTP - you're not using that protocol in your binding...
Also, since you're hosting this in Cassini, the address of your service will be dictated by Cassini - you don't get to define anything.
So my suggestion would be:
try to use http binding (just now for testing)
get this to work
once you know it works, change it to your custom binding and host it in IIS
So I would change the config to:
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="MyService.MyService" behaviorConfiguration="metadataBehavior">
<endpoint
address="" <!-- don't put anything here - Cassini will determine address -->
binding="basicHttpBinding"
contract="MyService.IMyService"/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
Once you have that, try to do a View in Browser on your SVC file in your Visual Studio solution - if that doesn't work, you still have a major problem of some sort.
If it works - now you can press F5 in VS and your service should come up, and using the WCF Test Client app, you should be able to get your service metadata from a) the address that Cassini started your service on, or b) the mex address (Cassini's address + /mex)
In case you rename the svc file make sure that your markup is correct.
You'll need to modify the default configuration and follow these steps:
1) Go to SVC file right click and select view markup
2) Make sure that that code behind and service pointing to correct the file and class name.
FYI - YOU CAN also get this error from a machine that is not having enough memory free. I got this error on a machine I run with 16 gigs of memory. I had a VM running with 6 gigs and a LOT of memory intensive apps. Close some down and this problem went away.
I still did get the error in the title of the question of
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.`
I did notice a larger message about memory though in using the WCF Test Client.
Hope this helps someone else.
In my case I was getting this error because the option (HttpActivation) was not enabled.
Add Serializable() before the type you expose
Serializable()
Public Class YourType
Put Serializable into <>
if working with .NET 4.0 WCF service - make sure Global.asax is not in the source directory. If it is , it is picked up at runtime and attempted to be compiled in...
changing the Binding Type from wsHttpbinding to basichttp binding in the endpoint tag and from wsHttpbinding to mexhttpbinginding in metadata endpoint tag helped to overcome the error. Thank you...
In my case, on commenting out the
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
in the web.config file was throwing "Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata".
For me the issue got resolved by doing the following:
Navigated to Tool --> Options --> Project and Solutions --> Web Projects
I could find the first check box "Use the 64 bit version of IIS Express of web sites and projects" was unchecked.
Selecting this check box helped me in launching the WCF Client.
VS Version : VS2019
I observed that when I removed SessionMode from the ServiceContract attribute, the issue went away.
Example:
[ServiceContract(SessionMode=SessionMode.Required, CallbackContract=typeof(ICallbacks))]
public interface IStringReverser
{
[OperationContract]
string ReverseString(string value);
}
to...
[ServiceContract()]
public interface IStringReverser
{
[OperationContract]
string ReverseString(string value);
}
I have tried several solutions mentioned over web, unfortunately without any success.
In my project, I have two interfaces(xml/json) for each service. Adding mex endpoints or binding configurations did not helped at all.
But, I have noticed, I get this error only when running project with *.svc.cs or *.config file focused. When I run project with IService.cs file focused (where interfaces are defined), service is added without any errors. This is really strange and in my opinion conclusion is bug in Visual Studio 2013.
I reproduced same behaviour on several machines(even on Windows Server machine).
Hope this helps someone.
Most of the time this happens due to less memory space. first check then try some other tricks .
The property IsOneWay=true may be true in the Operational contract of the interface.
Remove that property to get rid of this error.
In my case, the Webservice was generating the assembly with a different name than the project/service name. It was set like that by my predecessor developer working on the solution and I didn't know.
It was set to -
<serviceBehaviors>
<behavior name="CustomServiceBehavior">
<serviceAuthorization serviceAuthorizationManagerType="BookingService.KeyAuthorizationManager, BookingService" />
</behavior>
</serviceBehaviors>
So, the fix was the put the right assembly name in serviceAuthorizationManagerType. The assembly name can be obtained from following path of the service project:
Right click on the WCF svc project--> Select "Properties" --> From the list of tabs select "Application". Check the value against "Assembly name:" field in the list. This is the assemblyName to use for serviceAuthorizationManagerType which may not be the servicename necessarily.
<serviceBehaviors>
<behavior name="MyCustomServiceBehavior">
<serviceAuthorization serviceAuthorizationManagerType="BookingService.KeyAuthorizationManager, AssemblyNameFromSvcProperties" />
</behavior>
</serviceBehaviors>
remember to follow the instruction for serviceAuthorizationManagerType as mentioned on https://learn.microsoft.com/en-us/dotnet/framework/wcf/extending/how-to-create-a-custom-authorization-manager-for-a-service
It says -
Warning
Note that when you specify the serviceAuthorizationManagerType, the string must contain the fully qualified type name. a comma, and the name of the assembly in which the type is defined. If you leave out the assembly name, WCF will attempt to load the type from System.ServiceModel.dll.
Change to older Visual Studio.
Weird solution that worked for me.
I was using Visual studio 2017,
after changing to Visual Studio 2015 ,everything worked.
In Visual Studio:
project properties (right click on your project)
Debug -> Start Options
Make sure "Command line arguments" is empty
After Add this to your web.config file and configure according to your service name and contract name.
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="MyService.MyService" behaviorConfiguration="metadataBehavior">
<endpoint
address="" <!-- don't put anything here - Cassini will determine address -->
binding="basicHttpBinding"
contract="MyService.IMyService"/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
Please add this in your Service.svc
using System.ServiceModel.Description;
Hope it will helps you.
I had that issue. The solution is to startup VS with administrative privilege.