I have a WCF service that uses NetTcpBinding and I'd like to host it in a WPF application. The service seems to start correctly, but when I'm trying to get it's metadata using 'Add service reference' in visual studio I get this exception:
The URI prefix is not recognized.
Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8000/Mandrake/mex'.
My service project's App.config file:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="Mandrake.Service.OTAwareService">
<endpoint address="OTService" binding="netTcpBinding" contract="Mandrake.Service.IOTAwareService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint name="MEX" address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8000/Mandrake/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
And the code in the hosting application:
Uri baseAddress = new Uri("net.tcp://localhost:8000/Mandrake");
ServiceHost host = new ServiceHost(typeof(OTAwareService), baseAddress);
try
{
host.AddServiceEndpoint(typeof(IOTAwareService), new NetTcpBinding(), "OTService");
}
catch (CommunicationException e)
{
Console.WriteLine(e.Message);
host.Abort();
}
The solutions I found to the problem were mainly about adding the 'serviceMetaData' to the service config or providing a mex endpoint. Could you suggest something?
Edit:
Final config:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior0">
<serviceMetadata />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="Mandrake.Service.OTAwareService" behaviorConfiguration="NewBehavior0">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8036/OTService"/>
</baseAddresses>
</host>
<endpoint address="" binding="netTcpBinding" name="TcpEndpoint" contract="Mandrake.Service.IOTAwareService" />
<endpoint address="mex" binding="mexTcpBinding" name="MetadataEndpoint" contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
Hosting application:
host = new ServiceHost(typeof(OTAwareService));
host.Open();
I've managed to figure it out, after enabling the serviceDebug's includeExceptionDetailInFaults it was pretty clear.
Mandrake.Service.IOTCallback.Send operation references a message element [http://tempuri.org/:Send] that has already been exported from the Mandrake.Service.IOTAwareService.Send operation
So there was a Send(OTMessage) operation in the service contract and in the callback interface as well. A rather ugly mistake but I thought I would leave the solution here in case it helps anyone.
Related
I have created a wcf service, and want to run on secure way(https)
App.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1" behaviorConfiguration ="MyServiceTypeBehaviors">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8734/Service1/" />
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I have tried to change the base address from http to https.
And I have created self sign certificate from IIS and bind it with https with port 8374
Try with that configuration. I have changed the binding from BasicHttpBinding to BasicHttpsBinding and added "serviceCredentials" section where you have to select your certificate from some store on your machine.
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<services>
<service name="WcfServiceLibrary1.Service1" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint address="" binding="basicHttpsBinding" contract="WcfServiceLibrary1.IService1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceCredentials>
<serviceCertificate findValue="" storeLocation="LocalMachine" x509FindType="FindByThumbprint" storeName="My"/>
</serviceCredentials>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
</system.serviceModel>
</configuration>
P.S. If the web service is hosted in IIS then you don't need baseAddress and port. Port Binding is done from the IIS Manager
I have a problem with launching a WCF service using net.tcp endpoints. I'm getting an 10049 error.
My app.config:
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehaviour0"
name="Tinkl.Server.Services.Authentication.AuthenticationService">
<endpoint name="httpEndpoint"
address="reg"
binding="basicHttpBinding"
contract="Tinkl.Server.Services.Authentication.IRegistrationService" />
<endpoint name="httpEndpoint"
address="auth"
binding="basicHttpBinding"
contract="Tinkl.Server.Services.Authentication.IAuthorizationService" />
<!--
<endpoint name="tcpEndpoint"
address="net.tcp://78.26.210.203:50050/reg"
binding="netTcpBinding"
contract="Tinkl.Server.Services.Authentication.IRegistrationService" />
<endpoint name="tcpEndpoint"
address="net.tcp://78.26.210.203:50051/auth"
binding="netTcpBinding"
contract="Tinkl.Server.Services.Authentication.IAuthorizationService" />
-->
<endpoint name="mexEndpoint"
address="mex"
binding="mexHttpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://78.26.210.203:50076/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour0">
<!--<serviceMetadata />-->
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
There are 2 endpoints with netTcpBinding and 2 same exact with basicHttpBinding.
The problem appears when I'm trying to use netTcpBinding endpoints, I'm getting an error, but with basicHttpBinding it works fine...
I'm hosting the WCF service in a console application.
Program code
ServiceHost authenticationHost = new ServiceHost(typeof(AuthenticationService));
authenticationHost.Open();
Console.WriteLine("close <ENTER>\n");
Console.ReadLine();
authenticationHost.Close();
Maybe someone faced a similar problem?
If needed, I will give all the necessary additional information
Thank you in advance!
Try to replace lines
net.tcp://78.26.210.203:50050/reg
with
net.tcp://localhost:50050/reg
And the same for /auth endpoint.
I followed this(http://msdn.microsoft.com/en-us/library/ms733069.aspx) link and created a service and and a service host.
I added a webform client project to the solution. In order to check that my service is receiving a request I added a log in the service.
I selected my host and client to run at the same time by setting multiple start up project.
But I am having a problem making a communication between my service and client.Am i missing something in the configuration? i don't see exception at all(even though I selected CLR and JSRuntime exception, and managed debugging assistance ).
Here is my service configuration
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<client/>
<behaviors>
<serviceBehaviors>
<behavior name="meta">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="InboundMessage.Service.Operator" behaviorConfiguration="meta" >
<endpoint address="basic" binding="basicHttpBinding" contract="InboundMessage.Service.IOperator" name="basic"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<!--<endpoint address="" binding="wsHttpBinding" contract="IMetadataExchange" name="Ws" />-->
<host>
<baseAddresses>
<add baseAddress = "http://IP/InboundMessage.Service/"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="InboundMessage.Service.Operator"/>
</basicHttpBinding>
</bindings>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
Service Host:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="meta">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<diagnostics performanceCounters="ServiceOnly" />
<services>
<service name="InboundMessage.Service.Operator" behaviorConfiguration="meta">
<endpoint address="basic" binding="basicHttpBinding" contract="InboundMessage.Service.IOperator" name="basic"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<!--<endpoint address="" binding="wsHttpBinding" contract="IMetadataExchange" />-->
</service>
</services>
</system.serviceModel>
<system.web>
<compilation
debug="true" >
</compilation>
</system.web>
<system.webServer>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
a windowform Client configuration:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<system.web>
<compilation debug="true"></compilation>
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="meta" name="InboundMessage.Service.Operator">
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://IP/InboundMessage.Service/"/>
</baseAddresses>
</host>
</service>
</services>
<bindings>
<basicHttpBinding>
<binding name="InboundMessage.Service.Operator"/>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="meta">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
EDIT:
Used Tim's comment to install the service but I am having problem installing it.
I opened another question thanks Tim i am having problem installing the service on my local machine. I opened another question :Unable to install service using sc command
A few of things come to mind.
First (I'm not 100% sure, but this is based on my experiences) you can't run a Windows Service as a Windows Service through Visual Studio. You need to build the project and then install it, as directed on the page you linked to.
Secondly, you only need two configuration files, not three - one for the Windows Service (which is where the configuration for the service goes) and one for the client. I'm not sure what role you have (or believe you have) for the service host config file.
Third, your client config has entries for a service in the <system.serviceModel> section - you only need those if your client is also hosting a service, which doesn't appear to be the case in the question you've asked. You should remove the <services> section and add a <client> section, like this:
<client>
<endpoint address="http://IP/InboundMessage.Service"
binding="basicHttpBinding"
bindingConfiguration="InboundMessage.Service.Operator"
contract="InboundMessage.Service.IOperator" />
</client>
Note that I used the bindingConfiguration attribute above - without that, your client will use the default basicHttpBinding (which in your case won't matter because you didn't set anything other than the name, but if you had set non-default values you would want to tell the client which binding configuration to use).
In reality the simplest way (to get started) would be to build the Windows Service, install it and start it, and then add a service reference to it in your client (WinForm) application. That will generate everything you need and you can take a look at the config file to see the settings you need.
Hello I have a WCF service library project and I have created a WPF app to host it for testing and that works just fine, but I also created a web app to host it in IIS for production and when I try to connect to the IIs one I never can.
I am using a net.tcp bininding and I have gone in to IIS and added the net.tcp biniding to the web app and the web site.
Basically this is a duplex service with the methods marked as one way. When I call the method in the client the callback never gets called and I end up just sitting there waiting for several minutes before I close the application. When I self host the service I get a response almost immediately on the callback.
Also I have tried using localhost:808 and just localhost. If I use svcutil to generate the config it leaves the port off of the address. I don't get any errors that I am aware of, but I honestly don't really know how to tell if I get any errors it throws from IIS.
Also if I go to http://localhost:9595/EcuWebService/Service.svc I get the page that tells me to use svcutil to generate my client proxy.
As Jocke suggested below I attached a debugger and received this error: The service '/EcuWebService/service' does not exist.
Also here is the contents of my svc file:
<%# ServiceHost Language="C#" Debug="true" Service="EcuWeb.ServiceLib.Contracts.EcuWebServiceMain" %>
below is my Web.config:
<?xml version="1.0"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" minFreeMemoryPercentageToActivateService="1" multipleSiteBindingsEnabled="true"/>
<services>
<service name="EcuWeb.ServiceLib.Contracts.EcuWebServiceMain">
<endpoint address="net.tcp://localhost:808/EcuWebService/service" binding="netTcpBinding" bindingConfiguration="" name="netTcp_EcuWebServiceEndpoint" contract="EcuWeb.ServiceLib.Contracts.IEcuWebServiceMain">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="net.tcp://localhost:808/EcuWebService/mex" binding="mexTcpBinding" bindingConfiguration="" name="mexTcp_EcuWebServiceEndpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/EcuWebService" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
This is the config for the client app. The commented out endpoint is the endpoint that I use when not hosting in IIS and it works.
<?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>
<bindings>
<netTcpBinding>
<binding name="netTcp_EcuWebServiceEndpoint" />
</netTcpBinding>
</bindings>
<client>
<!--<endpoint address="net.tcp://localhost:5555/EcuWebService/service"
binding="netTcpBinding" bindingConfiguration="netTcp_EcuWebServiceEndpoint"
contract="EcuWebService.IEcuWebServiceMain" name="netTcp_EcuWebServiceEndpoint">
<identity>
<dns value="localhost" />
</identity>
</endpoint>-->
<endpoint address="net.tcp://localhost/EcuWebService/service"
binding="netTcpBinding" bindingConfiguration="netTcp_EcuWebServiceEndpoint"
contract="EcuWebService.IEcuWebServiceMain" name="netTcp_EcuWebServiceEndpoint">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<services>
<service name="Ecu.Service.Contracts.EcuServiceMain">
<endpoint address="service" binding="netNamedPipeBinding" bindingConfiguration=""
name="netNamedPipe_EcuClientEndpoint" contract="Ecu.Service.Contracts.IEcuServiceMain">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexNamedPipeBinding" bindingConfiguration=""
name="mexNamedPipe_EcuClientEndpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.pipe://localhost/EcuServiceClient" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
Ok I finally got this figured out.
First I had to add:
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:5555/EcuWebService" />
<add baseAddress="http://localhost/EcuWebService" />
</baseAddresses>
</host>
Then for the endpoint I just used:
<service name="EcuWeb.ServiceLib.Contracts.EcuWebServiceMain">
<endpoint address="service" binding="netTcpBinding" bindingConfiguration=""
name="netTcp_EcuWebServiceEndpoint" contract="EcuWeb.ServiceLib.Contracts.IEcuWebServiceMain">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
Then in the client I had to use:
<endpoint address="net.tcp://localhost/EcuWebService/Service.svc/service"
binding="netTcpBinding" bindingConfiguration="netTcp_EcuWebServiceEndpoint"
contract="EcuWebService.IEcuWebServiceMain" name="netTcp_EcuWebServiceEndpoint">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
When I added the port it didn't work, but once I removed it it worked no problem. Also I doubt the base address is required as IIS is giving the address anyway.
What happens? Do you get an exception? Can you browse it in the IIS?
Your service has:
endpoint address="net.tcp://localhost:808/EcuWebService/mex"
and the client:
endpoint address="net.tcp://localhost/EcuWebService/service"
I think you need provide more details to get a good answer.
I have self hosted a WCF service from a console application (HOST). I am calling HOST from another console application (PARENT). When I run PARENT, everything works fine like the WCF hosted successfully and instance of service reference is also getting created. The PARENT application is actually a plug-in for another big unmanaged application(BIG A). When I start the PARENT application from BIG A , the console application self hosts the service successfully. However I am getting following error while creating the instance of service.
Could not find default endpoint element that references contract 'CalculatorServiceReference.ICalculatorService' 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.
The configuration files are as follows.
•Configuration file of HOST
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior" name="HybridCalcService.CalculatorService">
<clear />
<endpoint address="mex" binding="mexHttpBinding" name="Mex" contract="IMetadataExchange"
listenUriMode="Explicit">
</endpoint>
<endpoint address="net.tcp://localhost:8523/CalcService" binding="netTcpBinding"
name="Tcp" contract="HybridCalcService.ICalculatorService" listenUriMode="Explicit">
</endpoint>
<endpoint address="HTTP" binding="basicHttpBinding" bindingConfiguration=""
name="HTTP" contract="HybridCalcService.ICalculatorService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/Hybridservice" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
•And the config of PARENT is
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior" name="HybridCalcService.CalculatorService">
<clear />
<endpoint address="mex" binding="mexHttpBinding" name="Mex" contract="IMetadataExchange"
listenUriMode="Explicit">
</endpoint>
<endpoint address="net.tcp://localhost:8523/CalcService" binding="netTcpBinding"
name="Tcp" contract="HybridCalcService.ICalculatorService" listenUriMode="Explicit">
</endpoint>
<endpoint address="HTTP" binding="basicHttpBinding" bindingConfiguration=""
name="HTTP" contract="HybridCalcService.ICalculatorService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/Hybridservice" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Can anyone help me in this issue?
I believe that the config info has to be in the config file of the main application. Adding that info to the config of BigA should solve the problem.
This looks pretty similar to what I did for a custom channel. if i remember correctly this would go into HOST, and then you wouldn't need anything in the other configs.