我想部署一个WCF服务到我的服务器,它的工作方式就像我希望它在本地一样。但在服务器上,我收到了404消息。JSON WCF部署服务器上的服务404
这是个什么样子,当我打电话给我的测试方法本地,如:
当我部署它,我仍然可以成功浏览到:
www.my域name.com/ Service1.svc
,但是当我去:
www.my域name.com/Service1.svc/test
我收到404错误。什么可能导致这个? 这是所有相关代码:
IService1.cs
namespace HighscoreWebService
{
[ServiceContract]
public interface IService1
{
[OperationContract]
[WebGet(UriTemplate = "Test",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare)]
string Test();
}
}
Service1.svc.cs
namespace HighscoreWebService
{
public class Service1 : IService1
{
public string Test()
{
return "Hello world!";
}
}
}
Web.config中的部分
<system.serviceModel>
<services>
<service name="HighscoreWebService.Service1"
behaviorConfiguration="jsonRestDefault">
<host>
<baseAddresses>
<add baseAddress="http:/xxxxxx"/>
</baseAddresses>
</host>
<endpoint name="jsonRestEndpoint"
behaviorConfiguration="RESTFriendly"
binding="webHttpBinding"
contract="HighscoreWebService.IService1">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="jsonRestDefault">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="RESTFriendly">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
我怀疑我在web.config中犯了错误。我对asp.net非常陌生,所以我可能犯了一些初学者的错误。但是因为这在本地工作,所以我猜可能是服务器配置有问题。或者在web.config中我需要做的一些事情来适应服务器配置。
感谢您阅读本文。
谢谢你的回应!我尝试添加地址=“测试”,但现在当我在本地导航时,我收到一条消息:“找不到端点” – Lage 2012-01-13 20:57:05
您可以发布您用于获取该服务的客户端代码吗? – Etch 2012-01-13 21:02:00
我还没有使用客户端,首先尝试让它在浏览器中工作。就像在本地工作一样。 – Lage 2012-01-13 21:31:31