How to connect WCF Service to a UWP Appl In Another computer - c#

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>

Related

System.ServiceModel.ServerTooBusyException

I hosted my WCF Service using Windows Service, but when I call the WCF method I get the following error:
System.ServiceModel.ServerTooBusyException: The HTTP service located
at
http://localhost:8733/Design_Time_Addresses/RahatWcfServiceLibrary/ServerDateTime/
is too busy. ---> System.Net.WebException: The remote server returned
an error: (503) Server Unavailable.
The App.Config in my WCF Service and Windows Service is as follows:
<?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="RahatWcfServiceLibrary.ServerDateTimeBehavior" name="RahatWcfServiceLibrary.ServerDateTime">
<endpoint address="" binding="wsHttpBinding" contract="RahatWcfServiceLibrary.IServerDateTime">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8733/Design_Time_Addresses/RahatWcfServiceLibrary/ServerDateTime/mex" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="RahatWcfServiceLibrary.ServerDateTimeBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="60" maxConcurrentSessions="60"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I solved the issue by adding '/mex' at the end of endpoint address in App.Config file in Windows Application that consumes the service.
<endpoint address="http://localhost:8733/Design_Time_Addresses/RahatWcfServiceLibrary/ServerDateTime/mex"

Communication between WCF server and client via LAN failed

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.

Why is my WCF wshttpbinding client doesn't work at another computer?

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"/>

WCF ContractFilter mismatch

I am hosting a WCF service on IIS. I can access the wsdl file with my browser. I can also add the Service Reference in Visual Studio for my client.
However, if I try to call Server.Test() an ActionNotSupportedException is thrown:
The message with Action 'http://tempuri.org/IWCFService/Test'
cannot be processed at the receiver, due to a ContractFilter mismatch
at the EndpointDispatcher. This may be because of either a contract
mismatch (mismatched Actions between sender and receiver) or a
binding/security mismatch between the sender and the receiver. Check
that sender and receiver have the same contract and the same binding
(including security requirements, e.g. Message, Transport, None).
I have two endpoints defined: One TCP.NET for the communication between the service and the client and one HTTP for metadata exchange.
Server Configuration (web.conf)
<services>
<service behaviorConfiguration="MyBehavior"
name="WCFServiceLibrary.Service.WCFService">
<endpoint address=""
binding="netTcpBinding"
bindingConfiguration="MyServiceEndpoint"
name="MyServiceEndpoint"
contract="WCFServiceLibrary.Contract.IWCFService">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://192.168.0.5:8080/Service.svc" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
Client Configuration (app.conf)
<?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="MyServiceEndpoint">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://192.168.0.5:808/Service.svc" binding="netTcpBinding"
bindingConfiguration="MyServiceEndpoint" contract="ServiceReference.IWCFService"
name="MyServiceEndpoint" />
</client>
</system.serviceModel>
</configuration>
In IIS I have set net.tcp (808:*) binding as well as http (8080) binding.
Sorry, nothing jumps out at me, but if I may suggest you set up tracing on the client, it should tell you what the actual problem is:
http://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx
Just a side note it seems to be the trend nowadays to reference the contract dll's in the client rather than use wsdl.
Shouldn't the baseaddress in web.config of the wcf service:
<host>
<baseAddresses>
<add baseAddress="http://192.168.0.5:8080/Service.svc" />
</baseAddresses>
</host>
be "net.tcp://..."
<host>
<baseAddresses>
<add baseAddress="net.tcp://192.168.0.5:8080/Service.svc" />
</baseAddresses>
</host>
A simple restart of the server did the trick!

Discover WCF hosted by Windows Service

In the solution, 4 projects : Business, the WCFService and the WCFServiceHost (a windows service) and a client
When I work in the solution, no problem, I can discover and create the proxy in the client.
When I install the host service, I start it but impossible to discover and create the proxy from visual studio with this : net.tcp://localhost:9100/MyApplicationWcf
Any idea ?
Thanks,
update #1
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service name="MyApplicationWcf.MyClassWcf">
<endpoint address="net.tcp://localhost:9100/MyClassWcf"
binding="netTcpBinding"
bindingConfiguration=""
name="MyClassWcf_Tcp"
contract="MyApplicationWcf.MyClassWcf" />
<endpoint name="mexHttpBinding"
contract="IMetadataExchange"
binding="mexHttpBinding"
address="mex" />
</service>
</services>
</system.serviceModel>
</configuration>
If you want to discover the service over net.tcp, you will need to define a MEX endpoint (metadata exchange) that uses the mexTcpBinding.
<behaviors>
<serviceBehaviors>
<behavior name="MexBehavior" >
<serviceMetadata/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="mexBinding" portSharingEnabled="true">
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="YourServiceImpl"
behaviorConfiguration="MexBehavior">
<host>
<baseAddresses>
<add baseAddress ="net.tcp://localhost:9100/MyApplicationWcf/"/>
</baseAddresses>
</host>
<endpoint address=""
binding="netTcpBinding"
contract="IYourServiceContract" />
<endpoint address="mex"
binding="mexTcpBinding" bindingConfiguration="mexBinding"
contract="IMetadataExchange" />
</service>
</services>
Do you have that??
Check out: How to: Publish Metadata for a Service Using a Configuration File for more information.

Categories

Resources