【问题标题】:WCF Service Works Locally but Returns 404 on Remote ServerWCF 服务在本地工作,但在远程服务器上返回 404
【发布时间】:2012-05-26 15:08:59
【问题描述】:

我创建了最简单的 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();
    }
}

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

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

任何想法如何解决?

谢谢!

【问题讨论】:

    标签: wcf http-status-code-404


    【解决方案1】:

    问题出在以下行:

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

    在服务器上部署时用适当的 url 替换它。

    【讨论】:

    • 啊!我从上一个问题而不是实际配置文件中处理了配置这是我真正得到的:''
    • 确保您用于引用服务的 URL 正确。将一个简单的 HTML 文件放在那里并尝试访问它以确保它不是一些权限问题。
    • 好的,我把端点改成下面这样,仍然从远程服务器得到404错误:mydomain.com/marathanInfoservice.svc" binding="webHttpBinding" bindingConfiguration="StreamedRequestWebBinding" contract= "MarathonInfo.IMarathonInfo" behaviorConfiguration="web">
    • 您是否尝试访问与 SVC 文件位于同一位置的 HTML 页面或图像或其他一些资源?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-30
    • 1970-01-01
    • 2016-09-08
    • 1970-01-01
    • 2014-05-06
    相关资源
    最近更新 更多