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.
Related
I have a WCF Service Application project in Visual Studio that contains the following files
ZooWebService.svc
WebConfig
I attempted to host the Web Service in IIS but when i browse to my web service from IIS the Web Service does not load at all. It just says "loading" in the browser.
Here is my WebConfig file:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="false" targetFramework="4.6.1" />
<httpRuntime targetFramework="4.6.1"/>
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="Default"
name="WCFWebService.ZooWCFService">
<endpoint address="" binding="basicHttpBinding"
contract="WCFWebService.IZooWCFService" />
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="Default">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I did the following so what have i done wrong?
Open IIS
Right clicked on Default Website
Selected "Add Application"
Populated "Alias" field
Populated "Physical Path" to directory of where the solution contents are
Clicked OK
Rebuilt the solution in Visual Studio
We don’t need to specify the base address in the configuration file which needs to be set up in the web site binding module.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/d42fc165-052d-476a-9580-1240b3d0293d/specify-endpoint-in-wcf-webconfig?forum=wcf
then we should enable the WCF feature in the IIS.
At last we could see the web service description in http://ip:port/xxxx.svc.
Feel free to let me know if there is anything I can help with.
For enabling the WCF in IIS, you may have to enable the HTTP activation feature for the .net framework first.
Some of links to do this
https://docs.sdl.com/LiveContent/content/en-US/SDL%20Tridion%20full%20documentation-v1/GUID-326D6F7B-08EC-43EB-A5A7-9C51DD9E555C
https://pubs.vmware.com/mirage-56/index.jsp?topic=%2Fcom.vmware.mirage.api.pg.doc%2FGUID-552D845B-E530-4898-A06B-4F73E668BEFF.html
Once this is done you may try to deploy WCF directly from the visual studio to your local IIS>
Right click on the WCFproject -> go to properties -> in properties window -> select web tab -> in servers section select Local IIS and click on Create Virtual Directory.
Now run the WCF from Visual studio, this will host the WCF in local IIS.
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.
Continue with this post
I created WCF Project host service on my machine from this tutorial:
http://www.aspdotnet-suresh.com/2011/06/introduction-to-wcf-wcf-tutorial-wcf.html
After my WCF service run on my machine i cannot connect with my client to my service and received EndPointNotFoundException (this happen from local and from remote machines) and this is not the case if my service running through visual studio.
what could cause this error ?
App.config:
<?xml version="1.0" encoding="utf-8" ?>
<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="WCFService.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8733/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="basicHttpBinding" 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>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the value below to false before deployment -->
<serviceMetadata httpGetEnabled="False"/>
<!-- 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>
</configuration>
You should run Service under administrator privileges. Windows services already have that's why you can run it without problem.
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>
One of my methods returns byte[], of a file. All other methods return either string objects or custom objects
I can view the WSDL via a browser and as i have used WCfExtras, I can even view the documentation.
In my test app, C# web application, I add the reference to my svc, hosted on a test server. I get an error as such:
The document was understood, but it could not be processed.
- The WSDL document contains links that could not be resolved.
- There was an error downloading ...
- Unable to connect to remote server
- No connection could be made because the target machine actively refused it
Content Type application/soap+xml; charset=utf-8 was not supported by service . The client and service bindings may be mismatched.
The remote server returned an error: (415) Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'..
If the service is defined in the current solution, try building the solution and adding the service reference again.
This is my app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="TestApp.Properties.Settings.TestDBConnectionString"
connectionString="Data Source=192.168.2.130;Initial Catalog=TestDB;Persist Security Info=True;User ID=sa;Password=xerox"
providerName="System.Data.SqlClient" />
</connectionStrings>
<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 behaviorConfiguration="TestApp.Service1Behavior"
name="TestApp.SearchService">
<endpoint address="" behaviorConfiguration="Sample.WsdlSampleEndpointBehavior"
binding="basicHttpBinding" bindingConfiguration="WsHttpMtomBinding" contract="TestApp.ISearchService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/TestApp/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="Sample.WsdlSampleEndpointBehavior">
<wsdlExtensions location="http://localhost:8731/TestApp/Service1/"/>
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="TestApp.Service1Behavior">
<!-- 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="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<extensions>
<behaviorExtensions>
<!-- Declare that we have an extension called WSDL Extras-->
<add name="wsdlExtensions" type="WCFExtras.Wsdl.WsdlExtensionsConfig, WCFExtras, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"/>
</behaviorExtensions>
</extensions>
<bindings>
<basicHttpBinding>
<binding name="WsHttpMtomBinding" messageEncoding="Mtom" transferMode="StreamedResponse" />
</basicHttpBinding>
</bindings>
</system.serviceModel>
</configuration>
Any ideas on how I would resolve this? Should I have 2 different bindings, one for methods returning non bytes[] and Mtom for method returning byte[]? If so how does one apply bindings per method exposed?
Tried running it with WcfTestClient.exe and this is the error
rror: Cannot import wsdl:portTypeDetail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporterError: Schema with target namespace 'http://tempuri.org/' could not be found.XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:portType[#name='ISearchService']Error: Cannot import wsdl:bindingDetail: There was an error importing a wsdl:portType that the wsdl:binding is dependent on.XPath to wsdl:portType: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:portType[#name='ISearchService']XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:binding[#name='BasicHttpBinding_ISearchService']Error: Cannot import wsdl:portDetail: There was an error importing a wsdl:binding that the wsdl:port is dependent on.XPath to wsdl:binding: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:binding[#name='BasicHttpBinding_ISearchService']XPath to Error Source: //wsdl:definitions[#targetNamespace='http://tempuri.org/']/wsdl:service[#name='SearchService']/wsdl:port[#name='BasicHttpBinding_ISearchService']Warning: No code was generated.If you were trying to generate a client, this could be because the metadata documents did not contain any valid contracts or servicesor because all contracts/services were discovered to exist in /reference assemblies. Verify that you passed all the metadata documents to the tool.Warning: If you would like to generate data contracts from schemas make sure to use the /dataContractOnly option.
I have the same problem. I was hosting the wcf on remote win2008 server on IIS. The solution that has worked for me was setting the host name when adding web site and don't leave it blank after setting all other data for hosting!
On the client app, do you have a reference to the WCFExtras assembly? The error appears to be saying that the binding is not recognized, which is, I assume, because of the extensions introduced by WCFExtras. Try adding the same extensions section to your client's config file as is in the server's config file.
Your binding is basicHttpBinding, but your binding configuration is wsHttpMTOMBinding.
This looks like a mismatch, however it could be just the names that you have given things.
Try opening the config file in the WCF config tool, this should tell you (refuse to open the file), if there are inconsistencies in your config file.
Hope this helps
Shiraz
This can't be a true answer, but after I removed WCfExtras references from my app.config file and deployed, things seem to work.
This is what I was trying to achieve, but have abandoned for time being
WCF Extras
If anyone has an idea of how and what I configured wrong, please advise on this column.
Many Thanks
The answer for me to be able to use the WCF Test Client is to set the set singleFile="true" in the web config like this.
<behavior name="Sample.WsdlSampleEndpointBehavior">
<wsdlExtensions location="http://localhost:8731/TestApp/Service1/" singleFile="true" />
</behavior>