I have a WCF rest webservice. It is working fine. I am wanting to understand the different configuration values available within the endpoint element.
In particular, I'm trying to understand the purpose of the address element. Changing the value doesn't seem to change how I can address the service. For this, I'm running the service from visual studio 2010 and cassini. the port number is set to 888.
with address set to an empty string i get... http://localhost:888/restDataService.svc/hello will return "hello world".
with address set to "localhost" i get... http://localhost:888/restDataService.svc/hello will return "hello world".
with address set to "pox" i get... http://localhost:888/restDataService.svc/hello will return "hello world".
It doesn't matter what value I set into the address field. It doesn't impact the url. My only explanation that I have is that the value is more for non-REST services.
<system.serviceModel>
<services>
<service behaviorConfiguration="MobileService2.DataServiceBehaviour开发者_如何学运维" name="MobileService2.DataService">
<endpoint address="pox" binding="webHttpBinding" contract="MobileService2.IRestDataService" behaviorConfiguration="webHttp">
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="webHttp">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="MobileService2.DataServiceBehaviour" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
I also have the following service contract
[ServiceContract]
public interface IRestDataService
{
[OperationContract]
[WebGet(UriTemplate = "hello")]
string Hello();
}
And in the .svc
<%@ ServiceHost Language="C#" Debug="true"
Service="MobileService2.RestDataService"
Factory="System.ServiceModel.Activation.WebServiceHostFactory"
CodeBehind="RestDataService.svc.cs" %>
And the 'code-behind'
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class RestDataService : IRestDataService
{
public string Hello()
{
return "hello";
}
}
Can you also show service element of your configuration? I think that your configuration is not used or you are accessing other instance of the application (did you configure Cassini to use port 80?) because your second and third test should return HTTP 404 Resource not found.
Correct addresses for your tests are:
- http://localhost/restDataService.svc/hello
- http://localhost/restDataService.svc/localhost/hello
- http://localhost/restDataService.svc/pox/hello
Check that your name in service element is exactly the same as name of service type (including namespaces) as used in ServiceHost directive in .svc markup.
精彩评论