Trying to publish my WCF Service to use with Rest - c#

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.

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

WCF service not running on other devices except server

I have WCF service which runs fine on my server machine using IP, it was working on client side(android studio) but suddenly it stopped working, I tried all solutions from internet but nothing seems to help, Service is sill working on Server browser/Postman.
Here's my web.config file if it is required:
<?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>
<services>
<service name="WcfService.Service1" behaviorConfiguration="WCFService.Service1Behavior">
<!-- Service Endpoints -->
<endpoint address="" binding="webHttpBinding" behaviorConfiguration="myWeb" contract="WcfService.IService1">
<!--
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>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="myWeb">
<webHttp/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="WCFService.Service1Behavior">
<!-- To avoid disclosing metadata information, set the value below to false 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>
<protocolMapping>
<add binding="basicHttpBinding" scheme="http" />
</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>
Also my Firewall is disabled completely.
When I ping service from mobile or other pc it gives error:
This site can't be reached.
Err_Address_Unreachable
First, can you call the service successfully from the other computer in the same LAN?
Second, what is the IP of your mobile device?
Finally, have you tried to restart your router/switch device in the current LAN? It is possible that there is something wrong with the router device which provides the Addressing function.
Feel free to let me know if there is anything I can help with.
If your computer's firewall is disabled check if your router has firewall and disable it.

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!

How to host a WCF service in IIS 7.5?

I am trying to host a WCF service in IIS Service 7.5 but from IIS Manager when I try to browse the svc file it is throwing me this error
Again when I try to run the svc file from the Visual Studio 2012 itself it opens perfectly from me
Where am I doing wrong ?
The web.config file is as follows :
<?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>
<services>
<service name="GreetMeWcfServiceLibrary.GreetMeService">
<endpoint address="" binding="basicHttpBinding" contract="GreetMeWcfServiceLibrary.IGreetMeService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</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>
</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>
And I have been trying to define the service first using WCF service library application and then trying to host using WCF service.
Moreover when I right click and click on the WCF configuration of the web.config file it says no service but I have added the reference to that service library dll.
Any help is much appreciated :(
In your WCF project tries to set target FrameWork 4 and perform the publication of the WCF and try again, the configuration file will be different and it should work.
Let me know
In your webConfig.xml try this
<?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>
<connectionStrings>
<remove name="XXXXX"/>
<add name="XXXXXX" connectionString="User ID=sa;Password=XXXX;Initial Catalog=XXXX;Data Source=XXXX\SQLEXPRESS"/>
</connectionStrings>
</configuration>
I suggest you review the server configuration to make sure all necessary IIS and WCF components are installed and configured properly. The following articles provide an overview of the issue and related troubleshooting suggestions:
http://www.dotnetscraps.com/dotnetscraps/post/e2809cHTTP-Error-50019-Internal-Server-Errore2809d-in-IIS-7-75.aspx
http://forums.iis.net/t/1166889.aspx

Default wcf service application has no endpoint defined

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.

Categories