0

我创建了最简单的 WCF 服务来尝试学习最基本的知识。当我在本地主机上运行它时,它工作正常。但是当我将它部署到远程服务器时,它会返回 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();
    }
}

根据我通过谷歌找到的内容,我很确定我需要添加一个新端点,但我无法成功地做到这一点。我的远程 URL 如下所示:

http://www.mydomain.com/service/MarathonInfoService.svc

任何想法如何解决?

谢谢!

4

1 回答 1

0

The problem is with the following line:

address="http://localhost:10298/MarathonInfoService.svc"

replace it with the appropriate url when you deploy it on the server.

于 2012-05-26T15:12:25.333 回答