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.
I am creating a event handler in MS Project Server. This event handler is calling a class library (dll file). The event handler is set and triggered from within the MS Project by clicks and not by code. In this class library, I am having a service reference to a web service. But, whenever, the event is triggered, I see the following error when I debug the class library via 'Attach to Process' option:
Could not find default endpoint element that references contract 'PSS.Project.ProjectSoap' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
Here is what my app.config looks like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="basicHttpBehavior">
<clientCredentials>
<windows allowedImpersonationLevel="Impersonation" />
</clientCredentials>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="basicHttpConf" sendTimeout="01:00:00" maxBufferSize="500000000"
maxReceivedMessageSize="500000000">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="500000000" />
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm"
realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
<binding name="ProjectSoap">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm" proxyCredentialType="Ntlm" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://xxxx/pwa/_vti_bin/PSI/ProjectServer.svc"
behaviorConfiguration="basicHttpBehavior" binding="basicHttpBinding"
bindingConfiguration="basicHttpConf" contract="SvcProject.Project"
name="basicHttp_Project" />
<endpoint address="http://xxxx/pwa/_vti_bin/PSI/ProjectServer.svc"
behaviorConfiguration="basicHttpBehavior" binding="basicHttpBinding"
bindingConfiguration="basicHttpConf" contract="SvcResource.Resource"
name="basicHttp_Resource" />
<endpoint address="http://xxxx/pwa/_vti_bin/PSI/ProjectServer.svc"
behaviorConfiguration="basicHttpBehavior" binding="basicHttpBinding"
bindingConfiguration="basicHttpConf" contract="SvcStatusing.Statusing"
name="basicHttp_Statusing" />
<endpoint address="http://xxxx/pwa/_vti_bin/PSI/Project.asmx?wsdl"
binding="basicHttpBinding" bindingConfiguration="ProjectSoap"
contract="PSS.Project.ProjectSoap" name="ProjectSoap" />
</client>
</system.serviceModel>
</configuration>
I also confirmed that the URL: http://xxxx/pwa/_vti_bin/PSI/Project.asmx?wsdl is working.
In the cs file, the error appears on the following code:
ProjectSoapClient projectSvc = new ProjectSoapClient();
When I do the same thing in a console app, it works, but when use a class library, it fails. I have read some Q&A's here and I know that when I am calling a service reference from a class library, I need to include configuration files of the service reference into the the class library, but I am not quite sure how and where to bring the config files from in my case and what portion of app.config should I add it to.
I have been able to call a WCF service within a Project Server Event Receiver DLL.
In order to do so, please follow these "tricks":
1.- For configuracion purposes, the DLL's (you code) execute within the Microsoft.Office.Project.Server.Eventing.exe process, which is located (in a default configuration) on: "C:\Program Files\Microsoft Office Servers\14.0\Bin". For custom installs open the task manager and right click the "Microsoft.Office.Project.Server.Eventing.exe" and select go to file. So, any configuration you need to be written in a file needs to be put in that directory insede the file: "Microsoft.Office.Project.Server.Eventing.exe.config". I have used this file to put a Database Connection String and I've been able to read it with the System.Configuration library. However, not all configuration sections works, I tried to put appSettings and a Sharepoint error was raised.
2.- For interaction with the Project Servers PSI, please use the WCF interface instead of the ASMX interface (I don't know why, but it works much better). I suggest using WCF programmatically (a quick search on google will net you how to set the bindings on the code).
I hope this helps you, I assure you it works. Now I'm trying to call ASMX service within the DLL (I'm still on it, if I find something I'll post).
I've installed MDS on our dev server and I can navigate through(and perform various functionality such as add users or create, add entities). I can't however get into the "Explorer". In here I get two Silverlight errors.
[HttpWebRequest_WebException_RemoteServer]
Arguements: Not Found
Debugging resource string are unavailable
etc....
The server is Win 2008 R2 Standard
IIS is 6.1 (Build 7601 SP1)
We're running SQL Server 2012
The client is running SL5 and the SL5 SDK
IIS is set up to run SSL and Win Auth(according to the trace logs, this is working, it's getting the principal). Everything else is Disabled
IIS can connect to the DB(via Database Manager in the Management section)
This is happening across all major browsers(IE, chrome, FF).
I have turned on trace logs for MDS(set to Verbose) and I don't see any errors/warnings
I ran SQL profilier as well and didn't see anything that would lead me to believe and error has occurred sql side.
The Event Viewer also doesn't have anything in it related to MDS/Silverlight.
I'm not sure if/how I can remote debug to the MDS website(it's preinstalled and precompiled)
A couple of snippets from the web.config
<bindings>
<wsHttpBinding>
<binding name="mdsWsHttpBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
<!--Non-SSL implementations.-->
<security mode="Transport">
<message clientCredentialType="UserName" />
<transport clientCredentialType="Windows">
<extendedProtectionPolicy policyEnforcement="WhenSupported" />
</transport>
</security>
</binding>
</wsHttpBinding>
<basicHttpBinding>
<binding name="mdsBasicHttpBinding" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<readerQuotas maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxDepth="2147483647" maxNameTableCharCount="2147483647" maxStringContentLength="2147483647" />
<!-- Non-SSL implementations.-->
<security mode="TransportCredentialOnly">
<message clientCredentialType="UserName" />
<transport clientCredentialType="Windows">
<extendedProtectionPolicy policyEnforcement="WhenSupported" />
</transport>
</security>
</binding>
</basicHttpBinding>
</bindings>
.. <snip> ...
<system.diagnostics>
<sources>
<!-- Adjust the switch value to control the types of messages that should be logged.
Use the a switchValue of Verbose to generate a full log. Please be aware that
the trace file can get quite large very quickly -->
<source name="MDS" switchType="System.Diagnostics.SourceSwitch" switchValue="All">
<listeners>
<add name="LogFileListener" type="System.Diagnostics.TextWriterTraceListener" initializeData="C:\Program Files\Microsoft SQL Server\110\Master Data Services\WebApplication\trace.log" traceOutputOptions="DateTime" />
<add name="EtwListener" type="System.Diagnostics.Eventing.EventProviderTraceListener, System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089" initializeData="{F2A341B8-CA5F-49ad-B00C-A82D3FCF948B}" />
<remove name="Default" />
</listeners>
</source>
</sources>
<trace autoflush="true" />
If anyone thinks the trace logs will help(or anything else), I can post them up(but they're huge).
My question is:
How can I debug, or somehow get a better error message, to point me in the right direction?
EDIT:
To add I found this in the trace log:
MDS Error: 0 : Service started successfully, Assembly version: 11.0.0.0, file version: 11.0.3000.0 ((SQL11_PCU_Main).121019-1325 )
DateTime=2013-01-07T15:09:14.1660484Z
MDS Error: 0 : ApiContractVersion: 5102
DateTime=2013-01-07T15:09:14.2753968Z
EDIT 2:
I've been able to dig out another error(after many config changes).
at Microsoft.MasterDataServices.Core.BusinessLogic.Member.GetEntityMembers(EntityMembers members, RequestContext context, OperationResult results)
SQL Error Debug Info: Number: 229, Message: The EXECUTE permission was denied on the object 'MemberGetCriteria', database 'MDS', schema 'mdm'., Server: SERVERNAME, Proc: , Line: 0
:
For some reason "MemberGetCriteria" is having some permissions errors.
Two things about permissions with the service account running the application pool in IIS:
1) It must have "Logon as a Batch" rights as per IIS requirements for running an application pool;
2) If you are requiring client certificates on your MDS website, MDS isn't set up to use certificates from the IIS web application to the MDS\Service\service.svc\bhh call, so you will need to make client certificates optional when that service is called.
web.config: I see you set up attempted to set up "Transport" / HTTPS security for the two WCF end-points but left tags instead of tags. You must make sure you did not mix and match the SSL and non-SSL sections and that you only commented the Windows / NTLM (or Kerberos if set up in the back-end) security mode section out, and uncommented the "SSL Implementation" section.
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
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.