Default wcf service application has no endpoint defined - c#

I just created a new WCF Service Application project in VS2010 (Premium), and it works out-of-the-box, but when I opened up the web.config file there are no endpoints present. The application works fine and I can open the address (http://localhost:50639/Service1.svc?wsdl) in a browser and I can see the contract and it all looks fine.
So my question is if the default project has uses a different approach rather then placing the information in the web.config? I can't see anything in the code either.
To show my point this is all that the web.config contains:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- 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>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
And still this service works and I can both connect and call the default methods (e.g. GetData())

That is not a "different" approach. It is a new approach in WCF 4.0 called simplified configuration. If you create project in .NET 4.0 you will get this simplified mode. If you create project in .NET 3.5 you will get old chatty configuration.

Related

VS 2022 WCF Service Application project template not working with Net TCP

I'm trying to get the simplest WCF Service Application to work with net.tcp and it's not working. Using VS2022, if I create a new project and select the WCF Service Application Template, the new project opens with a Web.config file, Service1.svc file and a IService.svc.
The Web.config looks like this,
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.7.2" />
<httpRuntime targetFramework="4.7.2"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- 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>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
If I run this sample project it loads the WCF Test client and shows the service running with the BasicHttpBinding. Perfect.
If I change the binding in the config file from <add binding="basicHttpsBinding" scheme="https" /> to <add binding="wsHttpBinding" scheme="http" /> and run the project, the WCF Test Client shows the WSHttpBinding. Great! Now if I change the binding in the config file from <add binding="wsHttpBinding" scheme="http" /> to <add binding="netTcpBinding" scheme="net.tcp" /> and run the project, the WCF Test Client shows the service running with the BasicHttpBinding. THERE'S NOT EVEN A BasicHttpBinding BINDING IN THE CONFIG FILE!!!!! WHERE THE HELL IS IT GETTING THAT FROM? I've been trying for days to netTcpBinding to work and no matter I do, nothing works. I figured I'd try the simplest thing I could do, which was start with a fresh blank project and make the simplest change, and still no luck. What am I missing. I can find nearly no information on getting this work.
First you have to understand the meaning of <protocolMapping>. The configuration in shows the default protocol mapping in the machine.config file.
You need to override this default mapping at the machine level by
modifying the machine.config file. Alternatively, if you just want to
override it application-wide, you can override this section in the
application configuration file and change the mapping for the
individual protocol schemes.
More generally, the HTTP system-provided bindings such as wsHttpBinding and basicHttpBinding are configured to turn things on by
default, whereas the netTcpBinding binding turns things off by default so that you have to opt-in to get support, for example, for one of the WS-* specifications.
You need to modify the configuration file, you can see how <netTcpBinding> is configured. If you host your service on IIS, you need IIS to have net.tcp enabled.
netTcpBinding In WCF Service With IIS Hosting
nettcpbinding
default-nettcpbinding
If you need simple projects to start with, I suggest you start with wcf's beginners tutorial.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/getting-started-tutorial

DotNetOpenAuth throwing an error in WCF

I'm using a third party library to fetch a collection of items
The API is based on DotNetOpenAuth.
The api call to fetch data works fine when tested through a simple console application.
However, My goal is to use this API within a web service.
When I test my Web service, the same API call to fetch data throws an exception:
"Error occurred while sending a direct message or getting the
response."
and the error code is 500 .
I find it strange that the same API call works from a console app but not from a web service call. Help!
the webconfig:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- 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>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
I figured out what was going on.
1) in the API, I was requesting for paged results, and it does not start with 0. It worked when I sent > 1 as the page offset.
2) I should have noticed that underneath this ambiguous error message, a server error code (500) was being returned . 90% of the time it means your sending crap to the server hehe.
problem solved!

Trying to publish my WCF Service to use with Rest

Im trying to publish my web services using IIS and there seems to be a problem with my web.config. I want to ultimatly publish my web services to a web host I have. I allready tried publishing the normal file system and uploading thos files to the webhost but I cant seem to get my service.svc to respond. Im thinking its because of my web.config here is the code. If you need anything else of my code please ask :D. Just as a note. The services work just fine when I run them with Visual Studio 2012. Also Im new at this, this is the first time I try to do this. :D
Web.config
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<services>
<service name="HotelLock.Service1">
<endpoint binding="webHttpBinding" contract="HotelLock.IService1" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- 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>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" >
</serviceHostingEnvironment>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
I uploaded the svc, the web.config and the bin with the dll to a host I have and all I get when I call the svc is
ServiceHost Language="C#" Debug="true" Service="HotelLock.Service1" CodeBehind="Service1.svc.cs"
I cant seem to call any of the other urls.
When I tried to use the IIS to use my service as localhost, the page does not load. I allready gave permition for the iis to use the webconfig. But I cant seem to get a normal error. I just cant load anything.
The config file looks OK. Maybe you should check the link that you call through the browser. The link should be like the following one:
http://www.yourdomain.com/ServiceName.ClassName.svc/UriTemplate
For your project, I think service name is HotelLock and the classname is Service1. I don't know the UriTemplate of your code but your interface (probably IService.cs) should have that information (e.g. [WebGet(UriTemplate = "ListData")]) Finally, your link looks like http://www.yourdomain.com/HotelLock.Service1.svc/ListData
I hope it works.

Adding WCF reference to a C# web application

I have a WCF project (:53763/WCFTestService.svc) and a web application(:50238/CSharp/test.aspx) in C#. I am trying to call the WCF project method in my web application. I have added the WCF project as a service reference in web application.
in test.aspx.cs file I have a method as follows
[WebMethod()]
public static string GetWCF()
{
WCFTestServiceClient client = new WCFTestServiceClient();
string result = client.XMLData("1122");
return result;
}
When I run this getting error :
Could not find default endpoint element that references contract
'TestWCFServiceReference.IWCFTestService' in the ServiceModel client
configuration section. This might be because no configuration file was
found for your application, or because no endpoint element matching
this contract could be found in the client element
.
When I add the WCF project as a service reference in my web application, the web.config file in the web application is not updated automatically. (No code is added by default at the time of adding reference).
Do I need to add anything in the web.config file for making it working?
web.config of WCF project is:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="WCFTestService.RestService" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="WCFTestService.IRestService" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
<!--<behavior>
--><!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment --><!--
<serviceMetadata httpGetEnabled="true"/>
--><!-- 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>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
It sounds like there's an error you're going to need to resolve when you reference your WCF project. Look on your information tab (not warning/errors) on Visual Studio when you add the reference and you'll see the errors. I'm guessing it'll have something to do with Newtonsoft.Json - which there are many posts about, such as Error adding service reference: Type is a recursive collection data contract which is not supported
In your configuration file you have only one endpoint with webHttpBinding that is used for restful address. So you can refer here to configure and test restful service. or add another endpoint to provide service metadata for SOAP client e.g.
<endpoint address="" binding="basicHttpBinding" contract="WCFTestService.IRestService" bindingNamespace="">
</endpoint>

webservice in class library Host Error

this is my first project in developing web service.
Its existing application. My project is classlibrary ..to this we added webservice.svc..
To see webservice wsdl ..what are the steps..? how to publish service in IIS.
please can anyone suggest me..
when i publish website i should publish as web deploy?
i tried to publish as webdeploy.. before that i created web site in IIS and tried to publish to hosted site in IIS ..publish succeed.. when i browse the service am getting below error, what does it mean..please help me..
provided as the Service attribute value in the ServiceHost directive, or provided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found.
copied my web config file..
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
I fixed my issue. Service Host service name not matching.. i tried to add test WCh service and compare .svc file..
fixed and running in IIS to..

Categories