我创建了最简单的WCF服务来尝试和学习基础知识。当我在我的localhost上运行它时,它工作正常。但是当我将它部署到远程服务器时,它会返回404。
配置:
<system.serviceModel>
<services>
<service name="MarathonInfo.MarathonInfoService">
<endpoint address="http://localhost:10298/MarathonInfoService.svc"
binding="webHttpBinding"
contract="MarathonInfo.IMarathonInfo"
behaviorConfiguration="Web"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="Web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="false" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
</configuration>
服务文件:
namespace MarathonInfo
{
public class MarathonInfoService : IMarathonInfo
{
public String GetData()
{
return "Hello World";
}
}
}
在界面中:
namespace MarathonInfo
{
[ServiceContract]
public interface IMarathonInfo
{
[OperationContract]
[WebInvoke(Method = "GET", UriTemplate = "/GetData", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
String GetData();
}
}
根据我通过Google找到的内容,我非常确定我需要添加一个新的端点,但是我无法取得任何成功。我的远程URL如下所示:
http://www.mydomain.com/service/MarathonInfoService.svc
任何想法如何解决?
谢谢!
答案 0 :(得分:0)
问题出在以下几行:
address="http://localhost:10298/MarathonInfoService.svc"
在服务器上部署时,将其替换为相应的URL。