Reputation: 1307
I have a REST service that returns a simple string. When I use WCF Test Client the service returns the expected value, but when I use a browser to access the service, the page comes up empty. Any ideas? All code is below.
CUCC.svc.cs
public class CUCC : ICUCC
{
public string AllAtms(string serviceKey)
{
//return new XElement("AllAtms") ;
return "test";
}
//public XElement AllOrganizationAtms(string serviceKey, int organizationId)
//{
// return new XElement("AllOrganizationAtms");
//}
}
ICUCC.cs
[ServiceContract]
public interface ICUCC
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Xml,
BodyStyle = WebMessageBodyStyle.Wrapped,
UriTemplate = "AllAtms/{serviceKey}")]
string AllAtms(string serviceKey);
//[OperationContract]
//[WebInvoke(Method = "GET",
// ResponseFormat = WebMessageFormat.Xml,
// BodyStyle = WebMessageBodyStyle.Wrapped,
// UriTemplate = "AllAtms/{serviceKey}/{organizationId}")]
//XElement AllOrganizationAtms(string serviceKey, int organizationId);
}
web.config
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<appSettings />
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
<httpRuntime />
</system.web>
<system.serviceModel>
<services>
<service name="CUCC.AllAtms" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="CUCC.AllAtms" behaviorConfiguration="web"></endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true" httpsGetBinding="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
<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="false" 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>
Sorry, forgot to include the url that I am using.
http://localhost:51870/CUCC.svc/AllAtms/testing
Upvotes: 1
Views: 3072
Reputation: 13077
The problem is here:
<service name="CUCC.AllAtms" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="CUCC.AllAtms" behaviorConfiguration="web"></endpoint>
</service>
This service definition claims that there is a service named AllAtms in the CUCC namespace; but there is no such service. When you invoke the service using the URI of your svc file, IIS attempts to find a service definition that matches the actual name of the service you are using. IIS gets the correct name for the service from the svc file but it doesn't find a service configuration matching the correct service name, so it returns HTTP 400 (Bad Request). You can see this result easily using Fiddler.
The service name should be the namespace qualified name of the implementation class and the contract should be the namespace qualified name of the interface. For example:
<service name="StackOverflow15910199.CUCC">
<endpoint address="" binding="webHttpBinding" contract="StackOverflow15910199.ICUCC" behaviorConfiguration="web" />
</service>
It must be the case that the WCF library project associated with this service has a properly defined service and endpoint in its App.config file, that's why the WCF test client is working. The test client should not have worked with service configuration you've posted.
Upvotes: 3