I don't have enough experience with WCF and its configuration and I don't know how to approach this problem. So I am sorry for this, possibly dumb, question.
I have virtual machine with windows service that hosts WCF. I want to communicate with this WCF from client running on local machine that runs this virtual machine. I can run the service locally with no problem, but when it comes to communicate with service on virtual machine I have really hard time to configure it properly. I want to use TCP connection without the use of IIS.
I tried to specify address of VM, alternate addresses and endpoints with no success. Can you advice me what is correct configuration?
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBindingConfiguration">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="WCFHostBehaviour" name="TestRunnerWCF.Service">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="NetTcpBindingConfiguration"
name="WCFHostNetTcpEndpoint" contract="TestRunnerWCF.IService" />
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
name="WCFHostMexTcpEndpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://192.168.10.25/Service" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFHostBehaviour">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
UPDATE 1:
I don't know how to add service reference in my client. If I use localhost I run service on my local machine and that is not desired.
Virtual machine runs in Hyper-V and have address 192.168.10.25. I can ping it from local machine. I don't use any port forwarding.
I can run client on virtual machine with this config:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="WCFHostNetTcpEndpoint">
<security mode="None" />
</binding>
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://192.168.10.25/Service" binding="netTcpBinding"
bindingConfiguration="WCFHostNetTcpEndpoint" contract="ServiceReference1.IService"
name="WCFHostNetTcpEndpoint">
</endpoint>
</client>
</system.serviceModel>
But when I try to run client on local machine I can't connect to my virtual machine.
Error: Cannot obtain Metadata from net.tcp://192.168.10.25/Service 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://192.168.10.25/Service Metadata contains
a reference that cannot be resolved: 'net.tcp://192.168.10.25/Service'.
Could not connect to net.tcp://192.168.10.25/Service. The connection attempt
lasted for a time span of 00:00:21.0324561. TCP error code 10060: A
connection attempt failed because the connected party did not properly
respond after a period of time, or established connection failed because
connected host has failed to respond 192.168.10.25:808. A connection
attempt failed because the connected party did not properly respond after a
period of time, or established connection failed because connected host has
failed to respond 192.168.10.25:808
As Reniuz point out, firewall in VM was blocking my connection.
Original comment:
So you need to specify VM's ip address. But first you need to ensure you can access it. Try to connect whit telnet . If you can't connect, first thing what you can do is to add inbound rule in VM's firewall (new rule-> select port->next-> enter wcf service port -> finish). Most likely the firewall is blocking in coming connection on your VM wcf port. – Reniuz
Related
I've waste xx hours for finding solution, but without success :(
I have IIS Server behind NAT, there is a WCF Service Host installed (on IIS).
Localy and over LAN Communication client-WcfService working property, but when i try to add service reference (over internet) to my wcf service host - in visual studio, i have an issue as below:
The request failed with HTTP status 400: Bad Request.
Metadata contains a reference that cannot be resolved:
I have redirected on my router port WAN to port Lan of my WCF Sercice. Its working property because when i connect over internet to http://[...] .svc file in browser i can see proper site.
my web.config
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mexBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="mexBehavior" name="KSPDJOBService.KSPDJOBService">
<endpoint address="" binding="wsHttpBinding" contract="KSPDJOBService.IKSPDJOBService" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/KSPDJOBService" />
</baseAddresses>
</host>
</service>
</services>
Any Ideas how to resolve my problem? i would be very thanksful for any tips.
Thanks.
Sorry for my english :)
I resolved this issue.
1st issue was: in port forwarding router has forwarding WAN port X to local port Y
2nd issue was: in svc/wsdl i had local url (thats why i had HTTP 400 error when trying to connect from internet)
SOLVED:
1st. So i've made forwarding WAN_port: Y to LAN_port: Y (the same ports)
2nd. I added in IIS Site - Binding hostname as WAN_domain_name.
Credits to : https://gavinmckay.wordpress.com/2009/03/24/howto-fix-wcf-host-name-on-iis
I am trying to host a svc service in my web application and I am trying to connect to it with a simple client application.
When the host is hosted in my own computer and solution, and I run the web application locally, everything works fine, meaning that I can add the reference to the service using add service reference in my client solution with http://localhost:6543/Hello.svc as the address and when I navigate to the service's url, it shows me the service's information as it should.
But when I publish my website, and I try to add the reference to my service using add service reference with http://myserver.com/Hello.svc as the address, i get the error message bleow:
There was an error downloading
'http://myserver.com/Hello.svc/_vti_bin/ListData.svc/$metadata'. The
request failed with HTTP status 404: Not Found. Metadata contains a
reference that cannot be resolved: 'http://myserverc.com/Hello.svc'.
The remote server returned an unexpected response: (405) Method Not
Allowed. The remote server returned an error: (405) Method Not
Allowed. If the service is defined in the current solution, try
building the solution and adding the service reference again.
and oddly when I navigate to myserver.com/Hello.svc, the browser starts to download the Hello.svc file instead of showing the service's details and information.
this is my website's web.config file:
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="crossDomain" crossDomainScriptAccessEnabled="true" />
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="WithDebug">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<services>
<service name="HelloWorldService.HelloService" behaviorConfiguration="WithDebug">
<host>
<baseAddresses>
<add baseAddress="http://myserver/Hello.svc"/>
</baseAddresses>
</host>
<endpoint
address=""
binding="webHttpBinding" bindingConfiguration="crossDomain"
contract="HelloWorldService.IHelloWorld" />
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
</system.serviceModel>
I think I am missing something big here, but since I am new to WCF, I don't know what it is.Any help would be appreciated and I am more than happy to issue more details about my project if needed.
Thanks in advance
You need to run ServiceModel registration tool
"This command-line tool provides the ability to manage the registration of WCF and WF components on a single machine. Under normal circumstances you should not need to use this tool as WCF and WF components are configured when installed. But if you are experiencing problems with service activation, you can try to register the components using this tool."
I have issue with hosing WCF service in console. Tried to search here but could not find solution of this issue even if it is similar to other issues here.
Hosting is very simple.
C# - Host
WCFSrv = new WCFService();
WCFSrvHost = new ServiceHost(typeof(WCFService));
udaWCFSrvHost.Open();
Config:
<system.serviceModel>
<services>
<service name="WCF_Service.WCFService">
<endpoint address="" binding="basicHttpBinding" contract="WCF_Service.IWCFService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:23456/WCFService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False"/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="BasicTimeouts" closeTimeout="00:00:30" openTimeout="00:00:30"
receiveTimeout="00:00:30" sendTimeout="00:00:30" />
</basicHttpBinding>
</bindings>
</system.serviceModel>
I can reach service through WcfTestClient from localhost and invoke methods offered by service.
I can reach service through WcfTestClient from same network, however cant invoke methods offered by service. Once I try to invoke method I receive error message:
There was no endpoint listening at http://localhost:23456/WCFService/ that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
...
Inner Exception:
No connection could be made because the target machine actively refused it 127.0.0.1:23456
at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
I tried to check whether there is port 23456 open and app is listening on that port through netstat -an and port 23456 is open and listening.
When I tried to modify base address (instead of localhost:23456 I put there real IP of server in network e.g. 10.xx.xx.xx) I was able to invoke methods as well but this is just workaround for internal solution.
Server and port should be open to external network and accessbile through internet. I tried to reach service from internet and I am able to reach service from internet (proof that port is open) but facing to same issue => cant invoke methods due to issue written above.
Does anyone have experience with same issue and can help me please?
Answered in Comments, put here for completeness.
Check the client config points at your server correctly and not localhost.
I'm new to WCF, but I've go the same issue latelly. I've just made a config file o the client project, and a wrote there the address of the endpoint:
<system.serviceModel>
<services>
<service name="WCF_Service.WCFService">
<endpoint address="" binding="basicHttpBinding" contract="WCF_Service.IWCFService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:23456/WCFService/" />
</baseAddresses>
</host>
</service>
</services>
You can use this reference: http://dotnetmentors.com/how-to-host-wcf-service-in-iis-7.aspx
From my point o view is very in handy. If it not works, try to recreate the project.
Sounds like you are binding to the wrong IP address try this:
<host>
<baseAddresses>
<add baseAddress="http://0.0.0.0:23456/WCFService/" />
</baseAddresses>
</host>
Using 0.0.0.0 instead of localhost will bind your service to all IPs on that host machine.
Thanks to all for support.
Solution for my issue:
Dont use WcfTestClient to test service from external network, at least in my case I faced issues described in my question.
For beginners simple advice when you have service hosted out of IIS
Use config file to define WCF settings in your project (e.g WCF Service Library)
Dont forget to copy setting from your WCF service project to Host application into app.config
When test from external network, use simple client app with own app.config, where endpoint has to lead to target service.
M.
I'm trying to get my WCF service working with netTcpBinding instead of wsHttpBinding, but I can't seem to get it working.
I added the net.tcp binding to IIS7.5 but the status is Unknown (and when I also remove the http binding it puts a big red X through the site and I have to add a new http binding before I can access any settings again). I already looked here and on Google but I could only find two or three posts about this issue without any true solutions.
What I have:
WAS service running, and also the Net.* services.
Added net.tcp in Advanced Settings in IIS.
WCF non-http is installed.
There seems to be a TCP listener running, as it shows in netstat that it is listening on my specified port: 809) and I also got firewall message (also tried disabling the firewall/antivirus, but it didn't help).
WCF Test Client results in this error:
Error: Cannot obtain Metadata from net.tcp://localhost:809/MyService.svc
My Web.config (as copied mostly from MSDN, for proper layout look here http://pastebin.com/Ru8p0T9N):
<services>
<service behaviorConfiguration="MyBehavior" name="WCFService.MyService">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="Binding1" name="MyServiceEndpoint" contract="WCFService.MyService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration="" name="MyServiceMexTcpBidingEndpoint" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:809/MyService.svc" />
</baseAddresses>
</host>
</service>
</services>
<behavior name="MyBehavior">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<netTcpBinding>
<binding name="Binding1"hostNameComparisonMode="StrongWildcard"sendTimeout="00:10:00"maxReceivedMessageSize="65536"transferMode="Buffered"portSharingEnabled="true">
<security mode="Message">
<transport clientCredentialType="None" />
<message clientCredentialType="None" />
</security>
</binding>
</netTcpBinding>
Everything works fine with wsHttpBinding but not with net.tcp. I tried several different settings in the Web.config from multiple sources but I keep ending up with the same problem.
Did you add net.tcp as an Enabled Protocol in IIS? Manage website => advanced settings => enabled protocols (comma delimited)
For people having the same problem: As I said before, I changed the Application Pool to Classic and it didn't work (http also didn't work anymore), but when I changed it back and recycled application pool it suddenly worked.
I don't understand what the problem is here. My wsHttpBinding works fine. Here is my configuration. Any help most appreciated.
<?xml version="1.0"?>
<configuration>
.....
<system.serviceModel>
<services>
<service behaviorConfiguration="DataService.Service1Behavior"
name="ODHdotNET.DataService">
<endpoint
address=""
binding="wsHttpBinding"
bindingConfiguration="largeTransferwsHttpBinding"
contract="ODHdotNET.IDataService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint
address="net.tcp://139.149.141.221:8001/DataService.svc"
binding="netTcpBinding"
contract="ODHdotNET.IDataService"/>
<endpoint
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://139.149.141.221:8000/DataService.svc" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="largeTransferwsHttpBinding2"
maxReceivedMessageSize="5000000" maxBufferPoolSize="5000000">
<security mode ="Message">
<message clientCredentialType="UserName"/>
</security>
</binding>
<binding name="largeTransferwsHttpBinding"
maxReceivedMessageSize="5000000" maxBufferPoolSize="5000000" />
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="DataService.Service1Behavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
edit: I am self-hosting in a Windows Service; I am not using IIS.
do you mean that a WCF client throws this error ?
if so:
please run the follwing at the command prompt:
netstat -ona | find "8001"
if this returns data, please post it
You need to add TCP support to your IIS.
To enable TCP, MSMQ, or named pipes communication specifically, perform the additional step of configuring support for the associated protocol. For TCP communication, bind the default Web site to a net.tcp port by using the Appcmd command-line utility. Appcmd is an IIS utility that enables you to administer virtual sites, directories,applications, and application pools.
%windir%\system32\inetsrv\appcmd.exe set site "Default Web Site" -
+bindings.[protocol='net.tcp',bindingInformation='808:*']
To support the other protocols, run additional commands that enable those protocols for the default Web site. At this point, you have configured the net.tcp protocol at the site level.
%windir%\system32\inetsrv\appcmd.exe set app "Default Web Site/OrderServiceHost"
/enabledProtocols:http,net.tcp
Please look at these for more detail: Extend Your WCF Services Beyond HTTP With WAS
Hosting WCF Services in Windows Activation Service
Make sure the port is open in windows firewall
Make sure your host is running when you invoke methods in client application.