Add WCF Service reference fails. And VS2008 exits - wcf

I have a super-simple WCF Service. I host it on my local machine using IIS7.
When I add a service reference to my service, Visual Studio tells me there was an error. I can click a Details link, and that bring up a dialog box saying: Object reference not set to an instance of an object.
I can build my WCF service with no problems, and my client app also builds successfully.
I can even use svcutil http://localhost/logservice/logservice.svc?wsdl to generate a client.
I've seen this error in my Windows Event Log/Viewer:
.NET Runtime version 2.0.50727.3053 - Fatal Execution Engine Error (706B7706) (80131506)
I found a hotfix online, but that won't install...
I think this has something to do with the client solution from where I add the service reference. I can add a service refenrece using the the "Discover services in solution" function. I just need to add a service reference in a solution elsewhere, so this is driving me nuts.
My system.serviceModel of web.config looks as follows:
<system.serviceModel>
<services>
<service behaviorConfiguration="LogServiceBehavior" name="LogService">
<endpoint address="" binding="wsHttpBinding" contract="ILogService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="LogServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>

I've tried isolating the problem, away from my current solutions and into a new solution with absolutely no complexity.
Create a new Web Site in Visual Studio from the WCF Service template.
Add a C# 3.5 Class Library project to the solution.
Build Solution.
Add Service Reference on ClassLibrary1 project, and click the discover button to discover the WcfService1 inside this solution.
You will see WcfService1 on the list, but when you click OK, or try expanding the service discovered, you will get the error. Sometimes VS2008 exits - without any prompt what so ever.
I've tried running C:\Windows\Microsoft.NET\Framework\v3.0\Windows Communication Foundation>ServiceModelReg.exe -r which doesn't help.
Has anyone encountered anything like this?

Related

"There was no endpoint listening at" issue with a IIS Hosted WCF Service consuming another web service

I have created a WCF service which is hosted in IIS and that tries to call another web service (3rd party) to return some data. When trying to connect the service fails with the following error:
There was no endpoint listening at https://xxx (3rd party ws) that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
And this is while, my service is up (i know from my echo method) and it works successfully if it is self hosted.
I have the whole and sections copied to the model of web.config exactly as it is for the self hosting test but something still is missing.
I have been through other similar problems reported but mine is little bit specific in that the service is kind-of hosting another one and that one is causing the issue.
I can try to exlain better with a real example:
There is a simple web service here: http://www.dneonline.com/calculator.asmx which I want to wrap inside our library and provide access to via an IIS hosted WCF.
So, a class library is created (Calculator project) to with one method, add to take two int arguments and use them to call the web service add method. The webservice is referenced as a Service Reference inside the library and is being addressed inside from within the config library app.config file like below:
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="CalculatorSoap" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.dneonline.com/calculator.asmx"
binding="basicHttpBinding" bindingConfiguration="CalculatorSoap"
contract="Service.CalculatorSoap" name="CalculatorSoap" />
</client>
</system.serviceModel>
</configuration>
Then there is a WCF class library (CalcService project) which uses the first class library to enable http endpoints. Again, the app.config file includes endpoints both as for the service itself and as a client of the class library. The app.config file looks almost like this:
<configuration>
<system.serviceModel>
<services>
<service name="CalcService.Calc">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8733/Design_Time_Addresses/CalcService/Calc/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<endpoint address="" binding="basicHttpBinding" contract="CalcService.ICalc">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<!-- Client endpoint, i.e. to be able to use the calculator.asmx service addressed in the class library -->
<client>
<endpoint address="http://www.dneonline.com/calculator.asmx"
binding="basicHttpBinding"
contract="Service.CalculatorSoap" name="CalculatorSoap" />
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I am able to test the whole thing via a console application that makes a call to the WCF service and receives an answer. The console application config file has only one client endpoint to the WCF like below:
<configuration>
<system.serviceModel>
<client>
<endpoint address="http://localhost:8733/Design_Time_Addresses/CalcService/Calc/"
binding="basicHttpBinding" contract="Calculator.ICalc" name="BasicHttpBinding_ICalc" />
</client>
</system.serviceModel>
</configuration>
My question is now how I can host the WCF service inside IIS? I have tried different ways but neither one worked. My current IIS project (which doen't work) looks like this:
1-Has project references to both prevoius projects (Class Library and WCF Service) so two dll files are being added to the references:
CalcService.dll
Calculator.dll
2-Has a CalcService.svc file which creates a ServiceHost toward the CalcService:
<%# ServiceHost Language="C#" Debug="true" Service="CalcService.Calc"%>
3-Has a web.config with cliend endpoint to calculator.asmx:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="CalculatorSoap" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://www.dneonline.com/calculator.asmx"
binding="basicHttpBinding" bindingConfiguration="CalculatorSoap"
contract="Service.CalculatorSoap" name="CalculatorSoap" />
</client>
<!-- some other settings -->
</system.serviceModel>
Now, when tested with a simple client to make a call to the calculator add method it fails with the following error:
There was no endpoint listening at http://www.dneonline.com/calculator.asmx that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
I don't know which message the endpoint is expecting, I could just assumed it has to be Service.CalculatorSoap as it worked before from the console application.
On the other hand, what confuses me is that a self hosted WCF also works (via http://localhost:8733/Design_Time_Addresses/CalcService/Calc/ from the config file in the WCF class library project).
I don't know what is missing here, is it something from the IIS configuration or permissions?
Or someting else like the windows firewall setting like explained in this post:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/bec3ab7a-310e-415f-b538-6d5681e5e53c/there-was-no-endpoint-listening-at?forum=wcf
Just note that since I am using a company computer, I'm not able to shut down the firewall. I can just turn on/off some of the rules.
I hope it is clear now what we are after.
We tested the solution on a cloud based machine and it worked fine. In the end it looked to be some firewall rules blocking the IIS outgoing calls and nothing was wrong in the configuration files or in the code.

Adding a WCF Tcp.net service to IIS for Visual Studio 2013 and how to test it

I am trying to deploy a wcf service I have created in Visual studio.
I am almost positive it is a configuration issue in either the wcf service config or in IIS itself.
The config I am using in the service is as follows:
<system.webServer>
<directoryBrowse enabled="true" />
</system.webServer>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="CandidateServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500" maxConcurrentInstances="500" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="SurveyService.SurveyService" behaviorConfiguration="CandidateServiceBehavior">
<endpoint address="/Survey/SurveyService" binding="netTcpBinding" name="CandidateServiceEndPoint" contract="Prometric.Census.SurveyService.ISurveyService" />
<endpoint address="/Survey/SurveyService/mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="false" />
</system.serviceModel>
I deployed the service once from visual Studio and pointed a new site on IIS with the following settings pointing to the deployment folder
Then after this within IIS you can see the site is in an unknown status:
It is from here that I can't connect to the service or find if it is running or not. I have tried the command /an : find /i "9015" and found nothing so I assume the service is not even running.
If I where to change the bindings on the WCF service and IIS to use http instead everything works fine. (Should say using http is not an option)
Also on top of not getting the service up and running I'm unsure how to test the service as TCP, Am I able to just add a service reference as you would with a http sefvice? As you can see I am pretty new to the tcp side of things and if I have left out any vital information please let me know so I can inslude it in the question.
This might help you :
https://rohitguptablog.wordpress.com/2011/06/16/configuring-wcf-service-with-nettcpbinding/
I followed this guide to make a net.tcp wcf service and it went smoothly. Also, are you sure that your folder has the required privileges? It can be tricky to use another folder than wwwroot/inetpub

Simplest Console Hosted WCF Service generates a 404 when browse to it

I have the very simplest Console based host for a simple WCF service. The app config for the service is:
<system.serviceModel>
<services>
<service name="MagicEightBallServiceLib.MagicEightBallService"
behaviorConfiguration="EightBallServiceMEXBehavior">
<endpoint address=""
binding = "basicHttpBinding"
contract = "MagicEightBallServiceLib.IEightBall" />
<!-- Enable the MEX endpoint-->
<endpoint address="mex"
binding ="mexHttpBinding"
contract ="IMetadataExchange" />
<!--Need to add this so MEX knows the address of our service -->
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/MagicEightBallService"/>
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="EightBallServiceMEXBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
The host program shows its running perfectly:
** Console Based WCF Host *
***** Host Info ******
Address: http://localhost:8080/MagicEightBallService
Binding: BasicHttpBinding
Contract: IEightBall
Address: http://localhost:8080/MagicEightBallService/mex
Binding: MetadataExchangeHttpBinding
Contract: IMetadataExchange
**************************************************
The service is ready
When I attempt to browse to or generate a proxy I get:
HTTP Error 404.0 - Not Found
I can't figure out what's wrong. You can't get any simpler than this!
I have faced the same problem when reading Troelsen's book and could not find any answer online. Anyway it seems that the problem is in the project type for MagicEightBallLib. Troelsen suggests that you create a Visual C# -> Windows -> Class Library project, but he does not explain what modifications you need to make for it to work. If you instead use the Visual C# -> WCF -> WCF Service Library project, it will automatically start the WcfTestClient.exe, and add new tab in project's Preferences called "WCF Options". I tried to compare the differences between .csproj files for both types of projects but there is just too many.
So the solution is to just start with the WCF Service Library project type instead of Class Library, and adjust names of interfaces and classes so they fit what is in the book.
If anyone knows which particular parts of the .csproj file are responsible for enabling this, I'd very much like to hear about it.
Hope this helps.
Instead of using localhost:8080 use 127.0.0.1:8080. That's how I got the example to work on my windows 10 machine.

Consuming a WCF hosted as Windows Service

I have a WCF Service (with installer) that I have built and installed in Windows Services. Opened up Admin Tools, Services, and started the service without a problem.
So now I'm beginning a new project (a simple Windows forms app). I want to consume my new WCF, but have no idea how. I can't seem to add a reference / add a service reference to it.
Any help would be greatly appreciated.
Thanks,
Jason
When the Windows service hosting your WCF service is up and running and properly configured, you should be able to use either Visual Studio's Add Service Reference or the command-line svcutil tool to connect to that service.
Just type in the address where the service lives.
This requires that your service has metadata exchange enabled (as a service behavior) as well as provides at least one MEX (Metadata Exchange) endpoint in its config. Do you have those available??
Service behavior:
<behaviors>
<serviceBehaviors>
<behavior name="mex">
<serviceMetadata />
</behavior>
</serviceBehaviors>
</behaviors>
and then your service must reference this configuration.
Service config:
<services>
<service name="YourService"
behaviorConfiguration="mex"> <!-- reference the service behavior with the serviceMetadata element ->
<endpoint .... (your regular endpoint here) />
<endpoint name="mex"
address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>

Error: Cannot obtain Metadata from http://172.16.70.125:8080/ when using WCF client to access service on another computer

I'm a newbie to WCF. So here's the thing : I have two systems, one running the wcf service and the other running the client.
I'm able to ping the IP of the service, and also able to see the link when I put it into my browser. (It shows me the service is up and running).
Howver, when I try to run wcftestclient from cmd, it gives me this error :
Error: Cannot obtain Metadata from http://172.16.70.125:8080/Service If this is a Windows (R) Communication Foundation service to which you have access, ...
I've been trying this all day, and its says the same thing.
Could someone please let me know what's wrong and how to fix this?
Thanks,
Thothathri
The WcfTestClient utility depends on the WSDL being available for the service. The WSDL is provided by the Metadata Exchange (or 'mex') endpoint. You are probably missing that endpoint. Look for something like this in your config, or add it if it is missing:
<service ... >
<endpoint ...(your usual endpoint for the service)... />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
Has your service exposed a metadata endpoint? Only relevent portions of config included
<services>
<service behaviorConfiguration="metadataBehavior" name="MyService">
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
Do you have metadata exchange enabled on your service? Your service should provide a mex endpoint for metadata in order for WcfTestClient to work AFAIK.
MSDN: How to: Publish Metadata for a Service Using a Configuration File