I have a WCF service with a simple Gallio unit test that calls the service. However, I am confused by the framework's behavior. When I start visual studio for the first time, and try to run the unit test, I get the following error:
System.ServiceModel.EndpointNotFoundException: There was no endpoint listening at http://localhost:43671/MyService.svc/MyService that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:43671
ErrorCode: 10061
However, if I right click on the Service Reference in the unit test project and do "Update service reference", a popup saying that ASP.NET Development server on port 43671 has been started shows up, and the unit test works fine.
How do I add the server start up code to my unit test so I don't have to "Update service reference" every time I want to run a unit test?
Thanks.
This happens because your WCF service host is not started when you run visual studio. Once you try to update the service reference Visual Studio automatically starts the WCF service host and after that your services will be accessible.
One way to solve this problem is to host your service(s) in IIS. This will ensure that the services will be accessible even if VS is not running.
Other solution would be to add reference (assembly reference) to your service and instantiate the service class directly. You don't need to have the service running to run unit tests against it. So if you have a service class called SomeServiceClass you could create an instance of this class in your unit tests (SomeServiceClass instance = new SomeServiceClass()) and write your asserts against it (without even hosting the service).
You can self host a service using ServiceHost. If you use that in the startup code of your unit tests, the WCF service will be hosted in the unit test.
I'm not sure where the app.config is for the unit tests you are hosting. However, you can always run the service in a separate AppDomain and set the AppDOmainSetup.ConfigurationFile
Related
I am trying to create wcf service and want to host on windows service.and install that service on windows.
so what I did I add wcf service library then built and run. after that its does successfully.
but when I create anther WCF appilcation so shows me this error= System.ServiceModel.AddressAlreadyInUseException.
SO how can I solve this issues please help to resolve this issue.
I install InstallUtil.exe but process not start on windows.
I want to host my WCF service on window and consume that service on my client application
First, I suggest you use WCF service application Template to create WCF service.
The error mainly indicates that the http address is already in use, we could change the port number and try it again.
At last, we had better use administrator account to install/run the windows service since the system layer driver (http.sys) manages the machine port. We could also use the below command to reverse the URL for the account runs the service.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/feature-details/configuring-http-and-https
https://learn.microsoft.com/en-us/windows/desktop/http/add-urlacl
Feel free to let me know if there is anything I can help with.
I created a sample WCFservice that provides four really simple services from 1 endpoint. Works fine within Visual Studio's (2010) WCF Test Client.
I was able to import the binding into SoapUI (4.5.2) and generate tests by referencing the wsdl. However when i execute any test i get a timeout.
Keep in mind that the service is only running on localhost via visual studio. But i can access the wsdl so i think it should be able to execute the tests. I keep getting timeouts and never hit service-side breakpoints.
Here's the endpoint i use in soapui
http://127.0.0.1:8732/Design_Time_Addresses/WcfMathServLib/MathService/
Looks like WCF Test Client uses this:
http://127.0.0.1:8732/Design_Time_Addresses/WcfMathServLib/MathService/mex
But neither really works for me. Any ideas?
I'm trying to test my net.tcp binded wcf service on my server machine, the service cannot be accessed from outside, does anyone know any tool that can be helpful to call my service on server 2008 machine?
Host the service in IIS. You can test the service using Integration Tests by adding the service Reference (net.tcp://localhost:8000/WCFTestService) in your test project.
Read this.
We created WCF Service and hosted in IIS in a specific machine.
WCF Client is hosted in some other machine which is there in the same LAN.
We were able invoke it. Suddently it started giving error. It is throwing some Timeout exception.
Please tell me the possible scenarios to get this kind of errors. If the WCF Client and WCF Service both are in the same machine, then it is not throwing any error.
Can you ping the service from the machine where the client is set-up?
Are there any firewalls causing this problem? But you said you were originally able to invoke it? are there any event logs to draw from?
You can try set up WCF loging
I have a WCF service that i've been able to communicate with fine while it's hosted locally.
I have it deployed to a web server in IIS now, and I can get the wsdl file without error by navigating to http://site.com:8000/service/servicename.svc?wsdl
in trying to test this, i've created a console app and was able to successfully add a service reference to this. But when I try to run a Get() method on the service reference, it just hangs with no response.
How can I begin to debug this?
Thanks!
When you have a service that works in dev but not in IIS, it is often due to a problem with the WCF configuration:
Is the configuration in place (since you can add service reference it probably is)
Is the protocol you are using available. The configuration you are using must match what is turned on. For example are you using nettcpip binding without WAS.