Unable to add service client for a net.tcp WCF service - c#

I am trying to add a client for a WCF service that is net.tcp based. When I use "Add Service Reference" and provide this URL:net.tcp://localhost/service1.svc, it gives following error.
The URI prefix is not recognized. Metadata contains a reference that
cannot be resolved: 'net.tcp://localhost/service1.svc'. Could not
connect to net.tcp://localhost/service1.svc. The connection attempt
lasted for a time span of 00:00:02.0051147. TCP error code 10061: No
connection could be made because the target machine actively refused
it 127.0.0.1:808. No connection could be made because the target
machine actively refused it 127.0.0.1:808 If the service is defined in
the current solution, try building the solution and adding the service
reference again.
I checked Windows Components for WCF non-http services, but they are already installed. This is the snap:
As you can see they are installed for .NET 3.5.1 and my service is built in .NET 4.5. Is this the problem? And how should I solve it? Because there is no option for .NET 4.5 in Windows Components List.
Following is the configuration of my WCF service:
<system.serviceModel>
<services>
<service name="CoreService.Service1" behaviorConfiguration="beh1">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/Service1.svc"/>
</baseAddresses>
</host>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.IAccountService"/>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.ICategoryService"/>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.ICommonService"/>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.IFollowerService"/>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.IInterestService"/>
<endpoint
binding="netTcpBinding"
bindingConfiguration="ultra"
contract="CoreService.IInviteService"/>
<endpoint
address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange"/>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="ultra"
maxBufferPoolSize="2147483647"
maxBufferSize="2147483647"
maxConnections="2147483647"
maxReceivedMessageSize="2147483647"
portSharingEnabled="false"
transactionFlow="false"
listenBacklog="2147483647"
sendTimeout="00:01:00">
<security mode="None">
<message clientCredentialType="None"/>
<transport protectionLevel="None" clientCredentialType="None"/>
</security>
<reliableSession enabled="false"/>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="beh1">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="True" />
<dataContractSerializer maxItemsInObjectGraph="65536" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>

It doesn't seem an incompatibility issue between the WCF HTTP or Non-HTTP Activation features and your service.
According to me, there's a missing or wrong configuration in IIS and that would explain the refused connection. To configure properly IIS with with net.tcp, have a look here.

Related

Wcf basicHttpBinding not working in Windows 8.1 app store

I wrote a Wcf Service and its configuration file is
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors" >
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="securityDemo">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="WcfDemo.EmpService" behaviorConfiguration="MyServiceTypeBehaviors">
<host>
<baseAddresses>
<add baseAddress="http://localhost:3003/"/>
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" contract="WcfDemo.IEmpService" bindingConfiguration="securityDemo"/>
</service>
</services>
</system.serviceModel>
This working fine for a console app or WPF app.
But when I am using same service for windows 8.1 app i am getting this exception
The HTTP request is unauthorized with client authentication scheme
'Negotiate'. The authentication header received from the server was
'Negotiate,NTLM'.
Deploy a WCF service on IIS Local (because IIS Express are not so flexible), set off Anonymous Authentication and set on Windows Integrated Authentication.
make service reference in target Win 8 app.
before using Service proxy add a lines with identification:
var client = new ServiceReference1.Service1Client();
client.ClientCredentials.Windows.ClientCredential.UserName = "windows user name";
client.ClientCredentials.Windows.ClientCredential.Password = "user passw";
call a service method
profit

There was no endpoint listening on mobile device but on console app works fine

I have WCF Service hosted on my computer (not on IIS). This service works fine, when I call it funnction from VS 2010. But if I want to call some method from Windows Mobile device i receive following error: There was no endpoint listening at....
My config of services is:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="DataSource" value="CMP\DATABASE" />
<add key="DataName" value="DAT" />
</appSettings>
<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>
<mexHttpBinding>
<binding name="MexBinding"/>
</mexHttpBinding>
<basicHttpBinding>
<binding name="Binding" maxReceivedMessageSize="2147483647" maxBufferPoolSize="2147483647">
<readerQuotas maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647"/>
<!-- UsernameToken over Transport Security -->
<!--<security mode="Transport">
<message clientCredentialType="Certificate" />
</security>-->
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Test.Service" behaviorConfiguration="Test.ServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://10.0.0.2:1918/Myservice/Service/"/>
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<!--<endpoint address="" binding="wsHttpBinding" contract="WcfServiceLibrary.IService">
-->
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<!--
<identity>
<dns value="localhost" />
</identity>
</endpoint>-->
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="ServiceA" binding="basicHttpBinding" bindingConfiguration="Binding" name="Service" bindingName="Binding" contract="Test.IService"/>
</service>
</services>
<!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>-->
<behaviors>
<serviceBehaviors>
<behavior name="Test.ServiceBehavior">
<!-- To avoid disclosing metadata information,
set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<!--<serviceAuthorization principalPermissionMode="None" />-->
<!-- 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 don't have set proxy on my mobile device.
You're using HttpBinding so some type of webserver is running on your box allowing the WCF hosting to work locally. So that's Cassini or IIS Express. Neither allows for remote connections without a bit of tweaking. Here's link of how to do that for IIS Express http://johan.driessen.se/posts/Accessing-an-IIS-Express-site-from-a-remote-comp‌​uter but it's a bit tedious though possible. I don't know if it's possible to allow Cassini to have remote connections.

Unable Host WCF Service with nettcpBinding on IIS 7.0

I am having a WCF ServiceLibrary which runs successfully on WCF Test Client.
Now I am trying to build a Website to Host this web service. I am using nettcp binding. My web.config file looks like this
<system.web>
<compilation debug="false" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="tcp_Unsecured" portSharingEnabled="true">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="tcpServiceBehavior" name="MarketFeedServiceLibrary.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="tcp_Unsecured"
name="data" contract="MarketFeedServiceLibrary.IService1" />
<endpoint address="mextcp" binding="mexTcpBinding" name="metadata"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="tcpServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
I am try to view in browser directly from Solution Explorer
But I get error as shown below
Could not find a base address that matches scheme net.tcp for the endpoint with binding NetTcpBinding. Registered base address schemes are [http].
I have tried all the solutions available on SO, youtube etc but no luck,
I tried:
Under IIS I have enabled http,net.tcp protocols
I have also gone through: How to: Install and Configure WCF Activation Components
N.B. I am a WPF App Developer, hence WCF and ASP.NET Website are new to me.
Thank You.
Edit: Testing Under WCF Client gives following error
Cannot obtain Metadata from net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.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. WS-Metadata Exchange Error URI: net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc Metadata contains a reference that cannot be resolved: 'net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc'. Could not connect to net.tcp://localhost:8080/MarketFeedSite/MarketFeedService.svc. The connection attempt lasted for a time span of 00:00:01.9968000. TCP error code 10061: No connection could be made because the target machine actively refused it 127.0.0.1:8080. No connection could be made because the target machine actively refused it 127.0.0.1:8080

How to test WCF service with TransportWithMessageCredential in VS2010 built-in web server

I'm developing a WCF Service with a custom UserNamePasswordValidatorwith a basicHttpBinding. This configuration, however, works only on HTTPS binding. Since Visual Studio 2010's built in web server does not support https, how can I test my custom validator? I keep getting Could not find a base address that matches scheme https for the endpoint with binding BasicHttpBinding. Registered base address schemes are [http]. error and, if I set the clientCredentialType to none, the error is gone, but the validator does not get called.
Below is my configuration.
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<extensions>
<behaviorExtensions>
<add name="ServiceErrorHandler" type="company.application.appserver.implementation.ServiceErrorHandlerBehaviorExtensionElement, AppSoftAppServer, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</behaviorExtensions>
</extensions>
<bindings>
<basicHttpBinding>
<binding name="SimpleBinding">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="DefaultBehavior" name="company.application.appserver.implementation.AppSoftUpdate">
<endpoint address="udt" binding="basicHttpBinding" bindingConfiguration="SimpleBinding"
name="AppSoftUpdate" bindingNamespace="http://company.application/update/2011/04"
contract="company.application.appserver.interfaces.IAppSoftUpdate" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="AppSoftUpdateMex" bindingNamespace="http://company.application/update/2011/04"
contract="IMetadataExchange" />
</service>
<service behaviorConfiguration="DefaultBehavior" name="company.application.appserver.implementation.AppSoftTransaction">
<endpoint address="udt" binding="basicHttpBinding" bindingConfiguration="SimpleBinding"
name="AppSoftTransacao" bindingNamespace="http://company.application/transaction/2011/04"
contract="company.application.appserver.interfaces.IAppSoftTransacao" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="AppSoftTransacaoMex" bindingNamespace="http://company.application/transaction/2011/04"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="DefaultBehavior">
<serviceMetadata httpGetEnabled="true" httpGetBinding="webHttpBinding"
httpGetBindingConfiguration="" />
<serviceDebug includeExceptionDetailInFaults="true" />
<ServiceErrorHandler />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom"
customUserNamePasswordValidatorType=" company.application.appserver.implementation.AppSoftValidacaoLogin, AppSoftAppServer" />
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Use IIS for this testing.
Open your project properties, go to the Web tab, hit Use local IIS radio button. This manual is valid for VS2010 too: Using Visual Studio 2008 with IIS 7
If IIS is not installed yet, install it first: How to install IIS.
You need to have Windows edition higher than Windows Home.
You will also need to create a self-signed certificate for your web site. This is easy to do in IIS 7: Self-Signed Certificates on IIS 7 – the Easy Way and the Most Effective Way
You cannot test such WCF service in Cassine (built-in web server in VS 2010). You must use local IIS or install VS 2010 SP1 and download IIS Express which is lightweight web server for development (can replace Cassini in VS and supports HTTPS with self signed certificates). IIS Express doesn't need any specific Windows edition and it works on all versions since Windows XP but it provides same features as IIS 7.5.

WCF (net.tcp) service: Works on all but one system

I've written created a WCF service inside a Windows service, and for some reason I can't figure out, I deployed the service on a bunch of systems (all nearly identical in OS and configuration), and it works on all but one server. The configuration for all deployments is identical except for the service's base address.
When the service is started, I get no exception when I open the ServiceHost, and when using netstat -anp I can see the socket has been opened by the service's process. I've set up Windows firewall logging for dropped packets, but the log file remains empty.
If I try accessing the WCF service from WCF Test Client, I get the following message:
Error: Cannot obtain Metadata from net.tcp://myhostname:9001/SysMonitorAgent
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: net.tcp://myhostname:9001/SysMonitorAgent
Metadata contains a reference that cannot be resolved: 'net.tcp://myhostname:9001/SysMonitorAgent'.
There was no endpoint listening at net.tcp://myhostname:9001/SysMonitorAgent that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
I've tried WCF logging, but the log file does not even get created.
The config for the service is as follows:
<system.serviceModel>
<diagnostics>
<messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true" />
</diagnostics>
<bindings>
<netTcpBinding>
<binding name="InterfaceServiceNetTcpBinding">
<security mode="None">
<transport clientCredentialType="None" protectionLevel="None" />
<message clientCredentialType="None" />
</security>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="InterfaceServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug httpHelpPageEnabled="false" httpsHelpPageEnabled="false" includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="SysMonitor.Agent.Interface.InterfaceService" behaviorConfiguration="InterfaceServiceBehavior">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="InterfaceServiceNetTcpBinding" contract="SysMonitor.Agent.Interface.IInterfaceService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://myhostname:9001/SysMonitorAgent" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
I'm kinda lost, because there is NO indication whatsoever as to why it's not working. Any help would be appreciated.
On the server you are deploying too is something running on port 9100?
It seems like it can not find the service. Have you tried changing the base address?
Typical if you deploy it on serval systems and it doesn't work on one it is configuration of the machine. I would check
.NET Versions
Make sure no Firewalls are set up on this machine preventing the binding
Check the port you are binding is open in this case 9100
Make sure any 3rd party .dll are included in the GAC or folder if needed.
Verify all the .dll and your code is up to date.
I see the error message says "net.tcp://myhostname:9001/SysMonitorAgent "
Did you try to replace it with the machine IP Address rather than using the host name?
In addition to David's points, check that the windows service is running.
Any errors in the Event log?

Categories