I am trying communicate between client and server, that are created with Microsoft WCF - netTcpBinding in C# and server runs as Windows Service. Server runs on my virtual LAN as single PC. But communication always failed with error:
An unhandled exception of type 'System.ServiceModel.Security.SecurityNegotiationException' occurred in mscorlib.dll
Additional information: The server has rejected the client credentials.
On localhost all works correctly. Client downloads ServiceReference from this IP address too.
Server app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="WCFHostService.MyServiceBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="WCFHostService.MyServiceBehavior" name="WCFServiceHost.MyService">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
name="NetTcpBindingEndpoint" contract="WCFServiceHost.IMyService">
<identity>
<dns value="" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
name="MexTcpBindingEndpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://10.0.0.1:8523/WCFTestService" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name = "netTcpBinding">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
</configuration>
Client App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBindingEndpoint" />
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://10.0.0.1:8523/WCFTestService" binding="netTcpBinding"
bindingConfiguration="NetTcpBindingEndpoint" contract="ServiceReference1.IMyService"
name="NetTcpBindingEndpoint">
<identity>
<dns value="
" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
I think that probably problem will be in security settings in config file. What is wrong there please? Becasue in TCPView on server system I see Remote address of MyService only "his local computer name", not * (all). Thanks for your replies.
Related
I wanted to connect a WCF service to a UWP application. When it is on the same computer it works fine. But when I use it on another computer it doesn't work. It cannot be found when I tried to add it using Add Service Reference. I'm new to WCF. If you can give some explained details, I will really appreciate that.
The current configuration file in the WCF Service host (App.Config)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".
NETFramework,Version=v4.8" />
</startup>
<system.serviceModel>
<bindings></bindings>
<client></client>
<services>
<service name="PMService1.MainService"
behaviorConfiguration="mexBehavior">
<endpoint address="MainServiceReference"
binding="basicHttpBinding"
contract="PMService1.IMainService">
</endpoint>
<endpoint address="MainServiceReference"
binding="netTcpBinding"
contract="PMService1.IMainService">
</endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://Pasan-Desktop:8086"/>
<add baseAddress="net.tcp://Pasan-Desktop:8090"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
Following this guide i try to Host WCF service in a Windows Service Using TCP.
this works fine on my computer but when install this service in other computer in the same network got an error: The server has rejected the client credentials
I try to disable Firewall but still same error (and the service running...)
from the client side Add service reference works fine and recognize the service.
this 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 name="WcfServiceLibrary1.Service1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration=""
contract="WcfServiceLibrary1.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://192.168.0.100:8523/Service1 " />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
192.168.0.100 is the server machine IP address.
Try to use this config for tcp binding:
<bindings>
<netTcpBinding>
<binding name="customTcpBinding" maxReceivedMessageSize="20480000" transferMode="Streamed" >
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
First, i host my wcf service in winform and i try to use wsHttpBinding. My client application work only in my development computer. Why is my WCF wshttpbinding client doesn't work at another computer? in another computer it showed "the caller was not authenticated by the service" when i execute the service
Here is my WCF winform host configuration (app.config) :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<connectionStrings>
<add name="DBCS"
connectionString="data source=localhost;DataBase=LatihanSP;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
</connectionStrings>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="XServerSvcBehavior">
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="XServerSvcBehavior" name="ServerTier.ServiceClient">
<endpoint address="" binding="wsHttpBinding" bindingConfiguration=""
name="XServerSvcBasicHttpEndPoint" contract="ServerTier.IServiceClient" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
name="XServerSvcMexHttpEndPoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:7777/SampleSvc" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
And here is my client app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="XServerSvcBasicHttpEndPoint" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:7777/SampleSvc" binding="wsHttpBinding"
bindingConfiguration="XServerSvcBasicHttpEndPoint" contract="ServiceRef.IServiceClient"
name="XServerSvcBasicHttpEndPoint">
<identity>
<userPrincipalName value="Kevin-EDP\Kevin" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
i try to change the userPrincipalName value to the name of the computer, still my client won't work, when i execute the service, it showed up "the caller was not authenticated by the service"
i am really sure my code is working, when i use basicHttpBinding, and when i look some solution over the internet, most of people suggest to use basicHttpBinding, but that's not the answer i want, i want to use wsHttpBinding for security reason
help me out guys, i am stuck almost 3 days, still can't figure it out
Set security mode to none. You can create binding configuration element in the WCF service config file
<wsHttpBinding>
<binding name="XServerSvcBasicHttpEndPoint">
<security mode="None"></security>
</binding>
</wsHttpBinding>
and use the configuration in the endpoint tag like
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="XServerSvcBasicHttpEndPoint"
name="XServerSvcBasicHttpEndPoint" contract="ServerTier.IServiceClient" />
At the client section change the identity to below format
identity impersonate="true" userName="domain\user" password="password"/>
I am trying to run my service with the WCF Test Client using netTcpBinding (service runs fine with basicHTTP). I am getting the following error
Error: Cannot obtain Metadata from net.tcp://chatmesh/mex 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://chatmesh/mex Metadata contains a reference that cannot be resolved: 'net.tcp://chatmesh/mex'. No DNS entries exist for host chatmesh. No such host is known
I don't see anything blatantly wrong that would cause the problem. Below is my app.config. Does anyone have any suggetions for me?
<?xml version="1.0" encoding="utf-8" ?>
<!--SERVICE App.config file-->
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NewBinding0">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="MachineLibrary.Machine1">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="NewBinding0"
name="" contract="MachineLibrary.IMachine1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://Chatmesh" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I am trying to configure a WCF service to support duplex communication to a client service and since I switched to WSDualHttpBinding I now get this on the service in IIS
There was no endpoint listening at http://exampple.com/Temporary_Listen_Addresses/06be1668-e09f-441c-9fc9-999e4922d4a8/1002945c-979b-484e-a2c5-fa3470b6706d that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. The inner exception is null and basically the service on the server is hosted in IIS then I have a self hosted service on the client machine that connects to the server and a client application that connects to the self hosted service. The wsDualHttpbinding is from the server to the self hosted service and the self hosted service exposes a named pipe for the client application to communicate with.
Here is the Web.config from the service:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<protocolMapping>
<remove scheme="http" />
<add scheme="http" binding="wsDualHttpBinding" />
</protocolMapping>
<bindings>
<wsDualHttpBinding>
<binding name="WsDualHttp_EcuWebBinding" />
</wsDualHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="EcuWebServiceBehavior" name="EcuWeb.Service.EcuWebService">
<endpoint address="/EcuWebService.svc" binding="wsDualHttpBinding" bindingConfiguration="WsDualHttp_EcuWebBinding" name="WsDualHttp_EcuWeb" contract="EcuWeb.Service.IEcuWebService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="EcuWebServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" minFreeMemoryPercentageToActivateService="1" multipleSiteBindingsEnabled="true">
<serviceActivations>
<add relativeAddress="EcuWebService.svc" service="EcuWeb.Service.EcuWebService" />
</serviceActivations>
</serviceHostingEnvironment>
</system.serviceModel>
</configuration>
Here is the App.config from my host application:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<client>
<endpoint address="http://localhost:51334/EcuWebService.svc/EcuWebService.svc" binding="wsDualHttpBinding" bindingConfiguration="WsDualHttp_EcuWeb" contract="EcuWebService.IEcuWebService" name="WsDualHttp_EcuWeb">
<identity>
<userPrincipalName value="myusername#domain.com" />
</identity>
</endpoint>
</client>
<behaviors>
<serviceBehaviors>
<behavior name="NetNamedPipeBehavior_EcuService">
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netNamedPipeBinding>
<binding name="NetNamedPipedBinding_EcuService" />
</netNamedPipeBinding>
<wsDualHttpBinding>
<binding name="WsDualHttp_EcuWeb" />
</wsDualHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="NetNamedPipeBehavior_EcuService"
name="Ecu.Services.EcuService">
<endpoint address="net.pipe://localhost/EcuNamedPipe" binding="netNamedPipeBinding" bindingConfiguration="NetNamedPipedBinding_EcuService" name="NetNamedPipeBinding_IEcuService" contract="Ecu.Services.IEcuService" />
</service>
</services>
</system.serviceModel>
</configuration>
And finally the App.config from the client test application:
<?xml version="1.0"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<system.serviceModel>
<bindings>
<netNamedPipeBinding>
<binding name="NetNamedPipeBinding_IEcuService" />
</netNamedPipeBinding>
</bindings>
<client>
<endpoint address="net.pipe://localhost/EcuNamedPipe" binding="netNamedPipeBinding" bindingConfiguration="NetNamedPipeBinding_IEcuService" contract="EcuServiceClient.IEcuService" name="NetNamedPipeBinding_IEcuService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
I have gotten this fixed thanks to another post on SO that pointed me to this article about WCF Duplex services. Duplex Article
Once I switched over to net.tcp and got everything setup to use it the duplex communication worked no problem.