I have an Ajax enabled web service within my website.
The service sits in a WebServices folder within the Root of the website, the folder also contains it's own Web.config (as the bindings for the Ajax web.config conflict the configs on another layer of my site).
I have added the web service to the scriptmanager in my master page and used JQuery to call the service within a page.
This is all working fine running locally in IIS 7 (Vista).
However when I publish the Website (locally to file system as we have to copy the files manually to our test environment) then copy the files to our test environment (running IIs 7.5 on Windows Server 2008 R2), the web service doesn't work and I get a Javascript error saying "Service is not defined".
If I browse to the service then I can view the wsdl with no problems however if I try and view service.svc/js (the same url the page is looking for) then I recieve a 404 not found error.
I've done a lot of Googling on the subject and while there are loads of suggested Web.config fixes, I have tried multiple combinations and so far nothing seems to be working.
The service it's self is very basic.
[ServiceContract(Namespace = "MyService")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]
public class MyService
{
[OperationContract]
public JSONObject DoWork()
{
...Do some logic
return JSONObject;
}
}
JSONObject is a class I created that just holds some properties to be sent to the page. As I said this is all working hosted in IIS locally.
---EDIT
Here's the Web.Config that sits in the same directory as the web service:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="default" />
</webHttpBinding>
</bindings>
<services>
<service name="MyWebsite.WebServices.MyService"
behaviorConfiguration="MyWebsite.WebServices.MyServiceBehavior" >
<endpoint address="" behaviorConfiguration="MyWebsite.WebServices.MyServiceAspNetAjaxBehavior" binding="webHttpBinding" contract="MyWebsite.WebServices.MyService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyWebsite.WebServices.MyServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MyWebsite.WebServices.MyServiceAspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
I also have the following section in my root web.config:
<system.serviceModel>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
I’ve managed to track down the issue.
It comes down to patching. The following article mentions an update to fix the issue in IIS 7.5 and Windows 7 but the patch is also applicable to Vista and Windows Server 2008.
http://support.microsoft.com/kb/2520479
There is a second option to fix the issue which involves reordering the Handlers in the IIS applicationHost.config file on the machine affected, I have tried this and it does in fact solve the issue.
The second option is described in the article above.
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.
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.
I have a WCF service page running only WebGets/WebInvokes over SSL - it works fine on my local machine (self signed cert). On production, however, I can reach service.svc (and it gives me the message about how to consume) but service.svc/AnyRequest returns a 404. Both environments are hosted in IIS 7.5.
I've enabled tracing and the service isn't even picking up any of the method requests (e.g. service.svc/SomeRequest), however it is processing service.svc just fine. It's also listening at https://computername.domain.net/path/service.svc - is this normal? Should it normally be pointing to https://publicfacing.com/path/service.svc?
Also note that the production server is hosting multiple sites within IIS.
Below is the system.serviceModel section of my web.config. The SSLBehave was suggested from here.
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None"></transport>
</security>
</binding>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="SSLBehave">
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="https" port="443"/>
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="UserManagement.ajaxAspNetAjaxBehavior">
<webHttp defaultOutgoingResponseFormat="Json" defaultBodyStyle="Wrapped" />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="UserManagement.ajax" behaviorConfiguration="SSLBehave">
<endpoint address="" behaviorConfiguration="UserManagement.ajaxAspNetAjaxBehavior"
binding="webHttpBinding" bindingConfiguration="TransportSecurity" contract="UserManagement.ajax" />
</service>
</services>
</system.serviceModel>
The first thing I do whenever I hit a 404 with a newly-developed WCF Web Service is checking the handler mapping required to interpret this type of call, because it's often the cause of the issue. There are several ways to work around the problem, many of which require a manual execution of the ServiceModelReg.exe console command: these are undoubtedly valid procedures but might also not work – or create additional problems – if your development machine has a particularly complex configuration. The resolution method I propose below is slightly longer to pull off, but has the advantage of solving the problem more safely and securely.
Open the Server Manager interface for machine management, usually present in both the Task Bar and the Start menu.
Go to the Dashboard (or Control Panel) and select Add Role or Feature to open the Wizard.
Select the Role-based or Feature-based installation type and the server you want to work on, that is, your local / local server.
Go to the Features section: Once there, expand the .NET Framework 3.5 Features node and / or the .NET Framework 4.5 Features node, depending on what you have installed: if you have both, you should perform the following step twice (for each one of them).
Expand the WCF Services section (if available), then select HTTP Activation (see screenshot below).
Continue until you complete the Wizard, then click Install.
Once the installation is complete, you should be able to run your WCF Service without incurring in the 404 error ever again.
For additional info regarding this specific issue and how to fix it, you can also read this post on my blog.
I would start by checking a number of things;
Permissions on the hosted directory?
.Net version is correct?
Have you added the certificate to the site?
Try putting an image in the same path, can you navigate to that (rule out the odd occasional path mappings)
Good luck!
You can implement transport level security using WsHttp bindings. See this article; in your bindings try this biding instead:
<wsHttpBinding>
<binding name="TransportSecurity">
<security mode="Transport">
<transport clientCredentialType="None"/>
</security>
</binding>
</wsHttpBinding>
The article mentions you should tie up the bindings with the end points.
I had the same problem. From what I read, WCF isnt NT Authenticated authorization (or HTTPContext compatible) by default.
I had to add this to my config file for the WCF service web.config in the section:
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
Which you did, plus this:
And on the actual service class definiation I had to add:
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class DataService : IDataDeliveryServiceContract
This fixed my problem.
Perhaps in your RouteConfig.cs file add this line:
routes.IgnoreRoute("{resource}.svc/{*pathInfo}");
So long as your .svc file is in the root of the application.
As you mentioned you can access your service by .svc extension service.svc but not in REST format service.svc/AnyRequest, the problem must be in routing integration.
add this to your web.config
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
<handlers>
<add name="UrlRoutingHandler" preCondition="integratedMode" verb="*" path="UrlRouting.axd"/>
</handlers>
</system.webServer>
In the IIS 6 The cause of this error must be Check that file exists setting of svc extention, make sure "Check that file exists is unchecked". For more information see IIS Hosted Service Fails.
To help others that find themselves stuck with this - It may be that your service name is not the fully qualified name, which it must be.
The following setting in web.config fixed a WCF .svc 404 on a HTTPS web site :
<webHttpBinding>
<!-- https -->
<security mode="Transport">
<transport clientCredentialType = "None" proxyCredentialType="None"/>
</security>
</binding>
</webHttpBinding>
I tried the above solutions, installing WCF Services, ensuring that there were proper permissions in the API directory and several other things.
While some of those were issues there was one issue for me that isn't mentioned above.
If Request Filtering is enabled for the entire server or the given site, make sure that .svc is a trusted file name extension, otherwise it will be blocked. Go to IIS > Request Filtering. Click on Edit Feature Settings. Check to see if "allow unlisted file extensions" is checked. If so, make sure that there is an entry in the list for .svc. Otherwise IIS will block the file from being served.
Our application accesses a WCF service, which is hosted by a Windows Service on a single computer. The client application and service always will be on the same computer.
I've created a Windows Service that hosts a WCF service. To test my Windows Service code, I created a console application that contains the same app.config and code as my Windows Service. I start the console application in one debugging thread, and launch my client in another debugging thread. Everything works perfectly and I can easily use the debugger.
Now the rub...
So, I created an installer and installed my Windows Service. After successfully starting it, I successfully added the Service Reference to my client using http://localhost/VssService within Visual Studio 2010. I successfully attached to the service via "Attach To Process". I launched my client in a debugging thread, but when I try to step into a remote method, I get "Unable to automatically step into the server. The debugger failed to stop in the server process." This happens for both [NetNamedPipeBinding_IVssService] and [BasicHttpBinding_IVssService]. I have been struggling with this for hours and have run out of ideas, so I hope that you can help me. I've included the app.config files for my Windows Service and Client application. Hopefully they will help.
I appreciate your taking time to read this question and hope that you can help be to resolve this problem...
Mike
===================== SERVICE APP.CONFIG =============================
<services>
<service behaviorConfiguration="VssServiceBehavior" name="ClientSaver.VssService.VssService">
<endpoint address="net.pipe://localhost/VssService/Pipe/" binding="netNamedPipeBinding"
bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />
<endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />
<endpoint address="http://localhost/VssService/MEX/" binding="mexHttpBinding"
bindingConfiguration="" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost/VssService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="VssServiceBehavior">
<serviceMetadata httpGetEnabled="True" policyVersion="Policy15" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
========================= CLIENT APP.CONFIG =============================
<endpoint address="http://localhost/VssService/" binding="basicHttpBinding"
bindingConfiguration="" contract="ClientSaver.VssService.IVssService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="VssServiceBehavior">
<serviceMetadata httpGetEnabled="true" policyVersion="Policy15" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
Ok. One way I use when VS debugging stops working is to place a System.Diagnostics.Debugger.Break() in a conventient place in the service code (say, constructor or method). This causes the JIT debugger to fire up and allows me to connect to the service with the code broken at that point with any VS instance I have.
Obviously you remove it from non debugging code.
You can't step across executable boundaries. Youll need to set breakpoint in your server code (that is project). Then from server`s project attach to the running windows service process (be carefull here ... you need to have latest server project running as windows service). Then, when you step in your Windows Forms app, it'll get caught by the server's breakpoint.
You should use internet explorer as default browser to debug your service...
Have a look at the debugging tools for windows. There are a couple of tools in here that are useful for debugging windows services.
Have you tried manually loading debug symbols? It once happened to me and it was happening because VS was not loading the symbols.
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>