I am trying to run my project.I am getting this error "Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata".
add this endpoint to your application.config file:
<services>
<service .....>
<endpoint binding="mexHttpBinding" bindingConfiguration="" name="mexService" contract="IMetadataExchange" />
<endpoint ...... the usual endpoints />
</service>
</services>
Related
I'm trying to develop a service with WCF but I can't find the certificate that I created, this certificate is located under TrustedPeple folder. So far this is my chunk of code that I wrote:
client.ClientCredentials.ServiceCertificate.SetDefaultCertificate(
StoreLocation.CurrentUser,
StoreName.My,
X509FindType.FindBySubjectName,
"WCfClient");
As you can see from the above code, I also tried to manually set the certificate characteristics but I still can't find it.
Also I'll post a portion of my conif xml file for a better understanding:
<services>
<service
name="XMLServices.CriDecServices.CriDecService"
behaviorConfiguration="wsHttpCertificateBehavior">
<endpoint name="CriDecPoint"
address=""
binding="wsHttpBinding"
bindingConfiguration="wsHttpEndpointBinding"
contract="XMLContracts.ServiceContracts.ICriDecService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/XMLServices/CriDecServices/CriDecService" />
</baseAddresses>
</host>
</service>
<service
name="XMLServices.UtenteServices.UtenteService"
behaviorConfiguration="wsHttpCertificateBehavior">
<endpoint
name="UserPoint"
address=""
binding="wsHttpBinding"
bindingConfiguration="wsHttpEndpointBinding"
contract="XMLContracts.ServiceContracts.IUtenteService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8766/XMLServices/UtenteServices/UtenteService" />
</baseAddresses>
</host>
</service>
</services>
This is the exception that I get:
"Client certificate not given. Specify a client certificate in ClientCredentials."
Can anyone help me out to understand why I can't seem to find my certificate? Thanks
If you look here you'll see that the store you are trying to use isn't the one from the trusted people folder but the one from the personal folder
you should use
StoreName.TrustedPeople
look here for more details https://msdn.microsoft.com/en-us/library/system.security.cryptography.x509certificates.storename(v=vs.110).asp
also most likely you need StoreLocation.LocalMachine.
We currently have a solution with only one WCF application, during the next two years the solution grows a lot.
It's around 70 different services.
We are using Windows Identity Foundation for security for majority, others use SSL and some don't have
I'm looking to restructure the application, I'am thinking about having multiple WCF application (one for business services, and other for backend services, etc...),
I think it can help for a lot for testing.
My question is:
Is there a way to construct a solution with multiple WCF applications without having to create and deploy multiple packages (not very usefull for deployments)
If I restucture the application, I will have 4 or 5 different services projects and also need an app.config file for each(not easy to maintain or upgrade in production environments)
You can have as many service assemblies in a WCF host as you like just make sure they have unique names. Every service dll gets its own project and the host stays at one project in the solution. Then create an app.config like this:
<services>
<service behaviorConfiguration="serviceBehaviour" name="DLSService.DLSService">
<endpoint address="DLSService" binding="basicHttpBinding" bindingConfiguration=""
name="basicHttpDLS" contract="DLSService.IDLSService" />
<endpoint binding="mexHttpBinding" bindingConfiguration="" name="mexDLS"
contract="IMetadataExchange" />
<endpoint address="DLSService" binding="netTcpBinding" bindingConfiguration=""
name="netTcpDLS" contract="DLSService.IDLSService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/ServicesHost/DLSService" />
</baseAddresses>
</host>
</service>
<service behaviorConfiguration="serviceBehaviour" name="RopsPreorderService.RopsPreorderService">
<endpoint address="RopsPreorderService" binding="basicHttpBinding" bindingConfiguration=""
name="basicHttpPreorderService" contract="PreorderService.IPreorderService" />
<endpoint binding="mexHttpBinding" bindingConfiguration="" name="mexRopsPreorderService"
contract="IMetadataExchange" />
<endpoint address="PreorderService" binding="netTcpBinding" bindingConfiguration=""
name="netTcpPreorderService" contract="RopsPreorderService.IPreorderService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/ServicesHost/PreorderService" />
<add baseAddress="net.tcp://localhost:9000/PreorderService" />
</baseAddresses>
</host>
</service>
</services>
I have a Unity based C# WPF application that has a Module that communicates to a WCF based project within the same solution.
The WCF dll works if i use the WCF test host make it an active service, but times out if i try to create a ServiceHost from code.
here is the code that is in the Unity Modules Initialization()
host = new ServiceHost(typeof(AtomCfgModelClient));
host.Open();
Here is my app.config section
<endpoint address="http://localhost:8080/AtomCfgModelService"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IAtomCfgModel"
contract="AtomCfgModel.IAtomCfgModel" name="WSHttpBinding_IAtomCfgModel">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<services>
<service name="AtomCfgModule.AtomCfgModel.AtomCfgModelClient" >
<endpoint address="" binding="wsHttpBinding" contract="AtomCfgModel.IAtomCfgModel" >
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint name="mex" address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/AtomCfgModelService" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior >
<serviceMetadata httpGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
ive turned off "start WCF Service Host when debugging " from the wcf project properties setting.
So, the above configuration seems to load ok from the wcf trace file, but when i go to use any of the services, i get a timeout without any information that i can see that lets me know what is causing the timeout.
here is the error message from the wcf trace, prior to this exception message, all the messages seem to succeed.
The HTTP request to 'http://localhost:8080/AtomCfgModelService' has exceeded the allotted timeout of 00:00:59.9840000. The time allotted to this operation may have been a portion of a longer timeout.
What is confusing is that if i use the WCF test host, then the above configuration works
String arg = "/service:\"" + Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "AtomCfgModel.dll") + "\" /config:\"" + Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "GISShell.exe.config") + "\"";
System.Diagnostics.Process.Start(#"c:\WcfSvcHost.exe", arg);
The above code running the wcfsvchost.exe uses the same config ( and WCF dll ) and i dont get the timeout.
Any points on how to debug/fix this would great.
I'm creating a WCF service which, at the moment, exposing a number of contracts using a basicHttpBinding. However, I now want to use the service locally on the same machine, and a netNamedPipeBinding seems more appropriate in terms of performance. For that reason, I want to expose the service using a named pipe and HTTP.
At the moment I'm doing this with the following configuration:
<service name="WCFService.MyService" behaviorConfiguration="serviceBehaviour">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/MyService" />
<add baseAddress="net.pipe://localhost/MyService" />
</baseAddresses>
</host>
<endpoint address="calculator" binding="basicHttpBinding" contract="WCFService.ICalculatorService" />
<endpoint address="database" binding="basicHttpBinding" contract="WCFService.IDatabaseService" />
</service>
This appears to work fine, but on closer inspection the endpoints are still using the basicHttpBinding. This works, but I get the impression it's creating unnecessary overhead.
Do I need to create an endpoint for each contract, and each binding type (i.e. basicHttpBinding and netNamedPipeBinding) or am I going about this completely wrong?
(If it's not clear, I'm fairly new to WCF!)
Yes, you need to specify multiple endpoints (1 endpoint per binding):
<endpoint address="calculator" binding="basicHttpBinding" contract="WCFService.ICalculatorService" />
<endpoint address="database" binding="basicHttpBinding" contract="WCFService.IDatabaseService" />
<endpoint address="calculator" binding="netNamedPipeBinding" contract="WCFService.ICalculatorService" />
<endpoint address="database" binding="netNamedPipeBinding" contract="WCFService.IDatabaseService" />
Every time my program runs vs adds the default configuration to my app.config file. At that run it works fine, but at the next run it actually tries to read the config.
The problem is that the default configuration has errors, it adds the attribute "Address", but attritbutes are not allowed to have capitals so it throws an exception.
This means I have to remove the bad section every run!
I've tried to configure the .config but it gives errors.
Here is the code that I use to host the server:
private static System.Threading.AutoResetEvent stopFlag = new System.Threading.AutoResetEvent(false);
ServiceHost host = new ServiceHost(typeof(Service), new Uri("http://localhost:8000"));
host.AddServiceEndpoint(typeof(IService), new BasicHttpBinding(), "ChessServer");
host.Open();
stopFlag.WaitOne();
host.Close();
Here is the client code that calls the server:
ChannelFactory<IChessServer> scf;
scf = new ChannelFactory<IService>
(new BasicHttpBinding(), "http://localhost:8000");
IService service = scf.CreateChannel();
Thanks for any help.
Edit: Sorry it took me so long, I've been trying to use DualWSHttpBinding instead (since I actually need the server to call client methods to anyway) but still generates the config file. Here's the entire auto-generated config file:
<?xml version="1.0"?>
<configuration>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup><system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Chess.ChessService">
<endpoint Address="" binding="wsHttpBinding" contract="Chess.IChessServer">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint Address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<Add baseAddress="http://localhost:8732/Design_Time_Addresses/Chess/ChessService/" />
</baseAddresses>
</host>
</service>
<service name="Chess.ChessClient">
<endpoint Address="" binding="wsHttpBinding" contract="Chess.IChessClient">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint Address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<Add baseAddress="http://localhost:8732/Design_Time_Addresses/Chess/ChessClient/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Visual Studio does not re-create the WCF configuration on every run. It will re-create the WCF configuration every time you do an Update Service Reference on your service reference in the project - but it definitely doesn't automatically do that before every run - there must be something else causing you grief here.
Furthermore, you're not connecting to the correct address - your server defines it here:
ServiceHost host = new ServiceHost(..., new Uri("http://localhost:8000"));
host.AddServiceEndpoint(..., .., "ChessServer");
and this results in your endpoint address on the server being
http://localhost:8000/ChessServer
However, you're client appears to attempt to connect to
http://localhost:8000/
and there's no service there.
A last point: if you set up all your things like endpoints, bindings etc. in code, any changes to the config shouldn't even bother you at all - there must be something else causing your problems.
You're quite mistaken. Attribute and element names may be upper or lower case.
What makes you think that the case of the attribute is the problem? And what makes you think that the app.config is changed on every run?