Run WCF service with many connections - c#

Is it possible to tun WCF service that could support several client types for example soap 1.1 and soap 1.2? Currently I have service with configuration below. I'm write that to support several connections I need to edit configuration file?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" sendTimeout="00:05:00" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8733/Design_Time_Addresses/WcfServiceLibrary1/Service1/"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="IService1" name="BasicHttpBinding_IService1" />
</client>
</system.serviceModel>
</configuration>

Related

Test a WCF service

This question must be newbie and i know it but i haven't found the answer for some time now. I have implemented a WCF service which i want to test. So when i click open in browser it opened something like
So i created the configuration file and the code file and i have input it into my solution in the same folder where the web service lies. When i have put the c# code mentioned above in a button of a web form this
EDIT: This is the output.config that i have mentioned above (i hope that is the client's config)
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_Icheck_for_quantity" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:51182/check_for_quantity.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_Icheck_for_quantity"
contract="Icheck_for_quantity" name="BasicHttpBinding_Icheck_for_quantity" />
</client>
</system.serviceModel>
</configuration>
If i run wcftestservice the following appears:

Unable to add service client for a net.tcp WCF service

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.

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.

wcf service wsHttpBinding over internet

Hello trying to get my binding to work over internet.
im using wsHttpBinding and trying to get it to work with soap.
i've tried NetTcpBinding and got my functions to show in the wcftestclient over the internet with my public ip and forwared my port to the right computer, but i could not call any functions failing with:
and i dont think soap can be used with NetTcpBinding so i've been trying to make this config work
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<services>
<service
behaviorConfiguration="VenatoWCF.Behavior"
name="VenatoWCF.WCFService">
<endpoint
address=""
binding="wsHttpBinding"
contract="VenatoWCF.IService"
bindingConfiguration="Binding">
</endpoint>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange">
</endpoint>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8734/WCF/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="VenatoWCF.Behavior">
<serviceMetadata httpGetEnabled="true" />
<useRequestHeadersForMetadataAddress />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="Binding" >
<security mode="Message">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
</bindings>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
</startup>
</configuration>
this can be consumed by soap but this this config i cant get any respone with soap or wcftestclient.
soap: Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://(My External ip):8734/WCF/?wsdl' : failed to load external entity "http://(My External ip):8734/WCF/?wsdl"
thank you for answers
EDIT1 sorry wrong config file for thoose who where fast enough to see :/
EDIT2
found in my wsdl file that in the bottom i have <soap:address location="https://dendei:8734/WCF/" /> isent that one supposed to be the one soap connects too and need to be "https://(my external ip):8734/WCF/" ???
how can i change this one? in config file? or in my program?
EDIT3
stumbled on this site while searching UseRequestHeadersForMetadataAddressBehavior
and that solved it localy so i could have localhost in my baseaddress <add baseAddress="https://localhost:8734/WCF/"/>
and it worked with soap so i got back the address it tries to connect too
and worked over the net :)
but with UseRequestHeadersForMetadataAddressBehavior you have to use .NET 4.0
You error message says that you use this Url http://(My External ip):8734/WCF/?wsdl to connect to your service with WcfTestClient. But you defined a different Url in you config file. Have a look a your baseAddress. Try this Url http://(My External ip):8734/Venato/mex?wsdl
Alright got it to work if i switched to 4.0 and use UseRequestHeadersForMetadataAddressBehavior instead of trying to access the wsdl file and change the soap:address that points to the local address still dont know how to do that. :)
and the connection problem was in my computer firewall that blocked connection the router accepted the connection and my own computer blocked it xD
will edit my quest with the config that worked for me cheers!

wcf service endpoint null

I have this App.config in my wcf service library:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="addr" value="net.tcp://localhost:22222/AdministrationService/"/>
</appSettings>
<system.serviceModel>
<services>
<service name="Watchman.WcfService.AdministrationService" behaviorConfiguration="MyBehavior">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:22222/AdministrationService/"/>
</baseAddresses>
</host>
<endpoint name="Ep1" address="net.tcp://localhost/AdministrationService/" binding="netTcpBinding" bindingConfiguration="DuplexBinding" contract="Watchman.WcfService.Interfaces.IAdministration"/>
<endpoint name="mex" address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyBehavior">
<serviceThrottling maxConcurrentSessions="10000"/>
<serviceMetadata httpGetEnabled="true" httpGetUrl="http://localhost/AdministrationService/Ep1/wsdl"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="DuplexBinding" sendTimeout="00:00:01">
<reliableSession enabled="true"/>
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0,Profile=Client"/>
</startup>
</configuration>
but I got error:
"The Address property on ChannelFactory.Endpoint was null. The ChannelFactory's Endpoint must have a valid Address specified."
It seems like application doesn't this tcp.net endpoint. Why?
I have this App.config in my wcf service library
You cannot have an app.config in a wcf class library and expect WCF to read settings from it. It doesn't make sense. Config files such as app.config are defined in the final executable application project (such as a Console application, WinForms, WPF, ...). Or if it is a web application you use a web.config. But there is not such thing as app.config for a class library. So you might need to include this WCF configuration in the app/web.config of the application using your class library.
You have specified a base address for net.tcp, so the address on the net.tcp endpoint becomes a relative address. So, effectively the address of the end point becomes net.tcp://localhost:22222/AdministrationService/localhost/AdministrationService/.
Change the address on the endpoint to a relative address and re-generate the proxy class using svcutil.
I just noticed that svcutil generates bad endpoint in wcf client project. There's
<endpoint binding="basicHttpBinding"
bindingConfiguration="DefaultBinding_IAdministration"
contract="IAdministration"
name="DefaultBinding_IAdministration_IAdministration" />"
instead of my net.tcp endpoint.
I also observed that's because of generation of ProxyFile.cs and App.config from
svcutil WcfServiceLibrary.dll
If I generate this files from metadata like:
svcutil net.tcp://localhost:8080/AdministrationService/mex /language:C# /out:ProxyFile.cs /config:App.config
then it works fine (in App config is described correct net.tcp endpoint)
Does anyone knows why cooperation svcutil with *.dll goes wrong?

Categories