我想部署一個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