Reputation: 1802
I developed a WCF service application and deployed it to IIS 8.
With a browser, when I go to http://localhost:6000/CustomService.svc, it shows "You have created a service" and other information. This means the service is successfully deployed.
But when I go to http://localhost:6000/testservice/date/2016/12/1, it showed HTTP 404 Not Found.
Here is service contract:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
namespace WCF
{
[ServiceContract]
public interface ICustomService
{
[WebGet(UriTemplate = "date/{year}/{month}/{day}", ResponseFormat = WebMessageFormat.Xml)]
[OperationContract]
string GetDate(string day, string month, string year);
}
}
Here is implemented class:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
namespace WCF
{
public class CustomService : ICustomService
{
public string GetDate(string day, string month, string year)
{
return new DateTime(Convert.ToInt32(year), Convert.ToInt32(month), Convert.ToInt32(day)).ToString("dddd, MMMM dd, yyyy");
}
}
}
Here is Web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service behaviorConfiguration="CustomServiceBehavior" name="WCF.CustomService">
<endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding" contract="WCF.ICustomService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:6000/testservice" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="CustomServiceBehavior">
<!-- 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="webBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
Where could the problem be? I basically copied most of the stuff from https://weblogs.asp.net/kiyoshi/wcf-using-webhttpbinding-for-rest-services.
Upvotes: 1
Views: 2537
Reputation: 13188
It worked with no problem for me.
using this URL:
http://localhost/WcfService1/Service1.svc/date/2017/1/31
and this config file:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="NewBinding0">
<security>
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="WcfService1.Service1">
<endpoint address="" behaviorConfiguration="NewBehavior0" binding="webHttpBinding"
bindingConfiguration="" contract="WcfService1.IService1" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="NewBehavior0">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Go to IIS Manager
right-click your .SVC file, select browse and make sure you have the correct base address in your config file. Your base address looks more like an IIS Express
address.
Upvotes: 1
Reputation: 286
Try using the WCF test client that comes baked into Visual Studio. It's located here: C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\WcfTestClient.exe. Open the test client, add the service and make your call.
You can use fiddler or some other network request capturing tool to see what URL is being requested by your service. Hopefully that should allow you to troubleshoot further.
Here is the MSDN for the WCF test client. https://msdn.microsoft.com/en-us/library/bb552364(v=vs.110).aspx
Upvotes: 0