WCF Service is not connecting to test client - c#

I keep getting this error when I run the test client
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
Cannot obtain Metadata from http://localhost:50507/Service1.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:50507/Service1.svc Metadata contains a reference that cannot be resolved: 'http://localhost:50507/Service1.svc'. The requested service, 'http://localhost:50507/Service1.svc' could not be activated. See the server's diagnostic trace logs for more information.HTTP GET Error URI: http://localhost:50507/Service1.svc There was an error downloading 'http://localhost:50507/Service1.svc'. The request failed with the error message:-- The type 'AgeCalculator.Service1', provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
I have already exposed the metadata of the service with the following code in the web.config file
<system.serviceModel>
<services>
<service name="AgeCalculator.CalculateAge" behaviorConfiguration="MetadataBehavior">
<endpoint address=""
binding="basicHttpBinding" contract="AgeCalculator.IService1">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="http://localhost/Service1.svc" binding="basicHttpBinding" contract="AgeCalculator.IService1"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MetadataBehavior">
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="http" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
I have looked at all current documentation and don't know what the issue is. May be a naming convention as I am brand new to WCF but not seeing this. I have scoured the internet and exposing the metadata articles to apply fixes and nothing has worked to date

Since you don't seem to be using the default port, it is best to specify the port in your service binding. Change your service definition like this:
<services>
<service name="AgeCalculator.CalculateAge" behaviorConfiguration="MetadataBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:50507/" />
</baseAddresses>
</host>
<endpoint address=""
binding="basicHttpBinding" contract="AgeCalculator.IService1" />
<endpoint address="mex"
binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="http://localhost:50507/Service1.svc"
binding="basicHttpBinding" contract="AgeCalculator.IService1"/>
</service>
</services>

Related

WCF Test Client EndPoint error

IN my WCF Service, the WCF Test Client reports the following error
System.InvalidOperationException: Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].
My App.Config is this:
<?xml version="1.0" encoding="utf-8" ?>
<services>
<service name="Practicon.SAPServiceLibrary.SAPDownloadService" behaviorConfiguration="debug">
<endpoint address="net.tcp://localhost:8082/SAPDownloadService" binding="netTcpBinding" contract="Practicon.SAPServiceLibrary.ISAPDownloadService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<host>
<baseAddresses>
<!--add baseAddress="http://localhost:8083/Design_Time_Addresses/Practicon/SAPServiceLibrary/SAPDownloadService/"/> -->
<add baseAddress="net.tcp://localhost:8082/SAPDownloadService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="debug">
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<!--<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false"/>-->
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<client>
<endpoint name="PracticonSAPDownloadEndPointClient"
address="net.tcp://localhost:8082/SAPDownloadService"
binding="netTcpBinding"
bindingConfiguration="BindingConfiguration"
contract="Practicon.SAPServiceLibrary.ISAPDownloadService">
<identity>
<servicePrincipalName value=""/>
</identity>
</endpoint>
</client>
<bindings>
<netTcpBinding>
<binding name="BindingConfiguration"
transferMode="Buffered"/>
</netTcpBinding>
</bindings>
I have got a net.tcp Endpoint - the Service runs fine, just that this error is reported in the WCF Hosting.
Can someone explain what I've done wrong and how to correct it?
Thanks
MM

WCF and Windows Store apps, ConfigurationErrorsException

I am getting a "ConfigurationErrorsException" when I try to create a new Instance of the service.
Edit: My App and the WCF service are not on the same machine. The Wcf service is running on a Windows Server 2012.
My Code in the Windows Store app looks like this:
var api = new ServiceRef.MyTestServiceClient(ApiServiceClient.EndpointConfiguration.BasicHttpEndpoint);
My WCF Configuration is (It's hosted as a windows service):
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MyTestService.MyTestService"
behaviorConfiguration="MyTestServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/"/>
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding"
name="BasicHttpEndpoint"
bindingConfiguration=""
contract="MyTestService.IMyTestService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyTestServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
The complete error message is:
The type
'Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior,
Microsoft.VisualStudio.Diagnostics.ServiceModelSink, Version=4.0.0.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' registered for
extension
'Microsoft.VisualStudio.Diagnostics.ServiceModelSink.Behavior' could
not be loaded.
I had the same problem. The following steps have solved the problem for me:
Close Visual Studio
Delete the .suo and .csproj.user files
Restart Visual Studio
Rebuild the project
It is probably because the referenced assembly is not part of the ".NET for Windows Store apps" library. According to this, http://msdn.microsoft.com/en-us/library/windows/apps/br230302(v=vs.110).aspx, diagnostics are not supported:
"Types and members that wrap operating system functionality (such as System.Diagnostics.EventLog and performance counters)."

IMetadataExchange could not be found

I'm trying to build two webservices with WCF (VS2010).
One webservice runs fine, but when i added a second webservice, then i got the following error:
The contract name 'IMetadataExchange' could not be found in the list
of contracts implemented by the service {0}. Add a
ServiceMetadataBehavior to the configuration file or to the
ServiceHost directly to enable support for this contract.
The second webservice is basically a copy of the first one. So i have no clue why i'm getting this error and how to solve this. Anyone any idea what the problem might be?
Here is my App.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service behaviorConfiguration="WcfEmguCV1.Service1Behavior" name="WcfEmguCV1.EvalService">
<endpoint address="" binding="wsHttpBinding" contract="WcfEmguCV1.IEvalService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfEmguCV1/Service1/" />
</baseAddresses>
</host>
</service>
<service name="WcfEmguCV1.Image">
<endpoint binding="wsHttpBinding" bindingConfiguration="" contract="WcfEmguCV1.IIMage">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration="" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Design_Time_Addresses/WcfEmguCV1/Service2/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfEmguCV1.Service1Behavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
<behavior name="WcfEmguCV1.Service2Behavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I found my problem. First of all, i was adding new data to the App.config through "Edit WCF Configuration" option. (Right click on the App.config file and you should see that option).
Since the first webservice config was already by default there, i had to add a new one. So i tried to enter the exact same data. But some things can't be added through that method.
Because when i took a closer look at my XML file i noticed i was missing this for the 2nd webservice:
<service behaviorConfiguration="WcfEmguCV1.Service1Behavior" ...>
So all i had to do was to add that to the 2nd node of 'service'.
behaviorConfiguration="WcfEmguCV1.Service2Behavior"

WCF Client does not consider Host Address

I have the following configuration file for WCF service. There is a host defined in the config. Still, when I print the service address from the client, it does not know about the host. The printed result is:
http://localhost:3187/Service1.svc/MyFolder
Why doesn’t it take into account the host name? What modification do we need to do for it?
Note: I am running from VS 2010 for running service and client website.
Service1Client myClientService = new Service1Client();
Response.Write(myClientService.Endpoint.Address);
Client Configuration (Autogenerated by Visual Studio)
<client>
<endpoint address="http://localhost:3187/Service1.svc/MyFolder"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IService1"
contract="MyWCFReference.IService1" name="WSHttpBinding_IService1">
<identity>
<userPrincipalName value="U16990#ustr.com" />
</identity>
</endpoint>
</client>
The server side configuration is:
<services>
<!--MyService-->
<service name="MyWCFServiceApplication.MyService"
behaviorConfiguration="WeatherServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:80/ServiceModelSamples/FreeServiceWorld"/>
</baseAddresses>
</host>
<endpoint address="MyFolder"
binding="wsHttpBinding"
contract="MyWCFServiceApplication.IService1" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WeatherServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
When a WCF service is hosted in an ASP.NET process, through either IIS or the ASP.NET Development Server (a.k.a Cassini), the baseAddresses setting in the service's configuration file is ignored since the service will always be reachable through the URL of the SVC file.
The URL you're seeing on the client is therefore correct:
http://localhost:3187/Service1.svc/MyFolder
As you can see, the base address of the service becomes the URL of the SVC file on the web server.
You're talking about a WCF client - yet, the config you posted only contains config for a service (the server side) ... (the <services> section).
I can't see any client configuration in what you posted - there ought to be a <client> section in your config somewhere

Can I use netTcpBinding for WCF services hosted outside of IIS?

My WCF service is being hosted as a Windows managed service, so I'm unsure of whether or not I can still use the netTcpBinding. I've tried following a couple of guides at MSDN, but for some reason my service always fails to start whenever I do the switch from basicHttpBinding. Perhaps there are additional steps that services outside of the IIS are required to undergo?
Yes you can host WCF service with netTcpBinding outside of IIS, in Windows service or even Console Application if you want to.
Here is config file sample:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="ServiceBehavior"
name="XX.XX.Service">
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="BindingConfiguration"
contract="XX.XX..IService" />
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8731/XXService" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding
name="BindingConfiguration">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
[Edit]
Problems with your config file:
base address is http instead of net.tcp
metadata endpoint is mexHttpBinding instead of metTcpBinding
security - by default windows authorization will be used, if test communication between to boxes, you might have permission problem. I suggest to start with security mode None and then adjust security when everything else works.
you don't need to specify httpGetEnabled for service behavior
if the port that you are going to use is already in use, you will not be able to start service
You absolutely can, and I'd go so far as to say you should.
Here's your problem:
<services>
<service name="Server.FileService" ...
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/Test/file"/>
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" contract="Server.IFile" />
<endpoint address="mex" binding="mexHttpBinding" ...
The net.tcp address must have a net.tcp:// prefix, not a http:// prefix.
I don't normally use baseAddress so can't give advice on that. I'd remove baseAddress and instead use
<endpoint address="net.tcp://localhost:8001/Test/file" ..
(note that I would also choose another port over 8000)

Categories

Resources