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>
Related
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.
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
This is a WCF REST service. The service works perfectly fine on my dev machine.
I have the service files in a subfolder of wwwroot called Services\
Admittedly I'm well versed at writing code, but no so well versed at using IIS to host/publish we services.
What I attempted to do was just copy the Services folder from my dev laptop to the server's wwwroot folder.
When this happens and I try to access the service on the server I get some strange error that I don't understand (well I sort of understand it just don't know why it's happening)
"The type 'BooksService.Service1', provided as the Service attribute value in the ServiceHost directive, or profided in the configuration element system.serviceModel/serviceHostingEnvironment/serviceActivations could not be found."
Service1.cs looks like so in my project:
namespace BooksService
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in both code and config file together.
public class Service1 : IDataService
A decent portion of my web.config is based on google recommendations so it's probable I may not understand something or just have it plain wrong.
Web.Config looks like:
***<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<services>
<service name="BooksService.Service1">
<endpoint address="" binding="webHttpBinding" contract="BooksService.IDataService" behaviorConfiguration="restfulBehavior"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost/bookservice" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="restfulBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<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>
</system.serviceModel>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration>***
My service file looks like this:
<% #ServiceHost Service="BooksService.Service1" %>
Then there is a bin folder which contains my .dll
So the folder layout is as follows:
c:\inetpub\wwwroot\SERVICES\BookService\bin
Where service.svc is in the BookService folder and the assembly is in the bin folder.
What step(s) might I be missing?
First, you need to create an application in IIS and point the virtual directory to your application folder: c:\inetpub\wwwroot\SERVICES\BookService.
Then you need to update your service base address accordingly:
<baseAddresses>
<add baseAddress="http://localhost/services/bookservice" />
</baseAddresses>
You can test the url by typing it in your browser and browsing to the service location.
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.
We have a web service located at [website]/Api/HmlApi.svc/soap which normally works OK. Its not SSL.
In this particular site we can see the .svc page fine in a browser, but the client application attempting to access this service gets a http 404 error. Endpoint not found.
The website has config as follows.
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
</serviceHostingEnvironment>
<!--Set up the service-->
<services>
<service behaviorConfiguration="SOAPRESTDemoBehavior" name="HmlApi">
<endpoint address="soap" binding="basicHttpBinding" contract="VLSCore2.Interfaces.IHmlApi" />
</service>
</services>
<!--Define the behaviours-->
<behaviors>
<serviceBehaviors>
<behavior name="SOAPRESTDemoBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="SOAPRESTDemoEndpointBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
The log in the website has the following error:
/Api/Hmlapi.svc/soap - The controller for path was not found or does not implement IController
This to me points to the url being right - we are hitting the site, we can get to the svc but somehow it does not route to the soap endpoint as setup as normal in the config above.
Any ideas to why in the case of this one site it might not work? Anything else we can check?
Make sure you have correctly configured the WebApi route config. You may have them in the Global.asax.cs or if you are in a MVC4 or MVC5 project, in the App_Start folder, WebApiConfig.cs.
If you have the routes configured correctly, then are you putting the service configuration in the correct configuration file?
Greetings!