部署服务器JSON WCF服务404 [英] JSON WCF Service 404 on deployment server

查看:158
本文介绍了部署服务器JSON WCF服务404的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个WCF服务部署到我的服务器,它只是我希望它在当地的方式。但在服务器上我得到一个404的消息。

I'm trying to deploy a WCF Service to my server, it works just the way I want it to locally. But on the server I get a 404 message.

这是个什么样子,当我打电话给我的测试方法像本地:

This is what it looks like when I call my test method locally:

当我部署它,我仍然可以成功浏览到:

When I deploy it I can still successfully browse to:

www.my域name.com/Service1.svc

www.my domain name.com/Service1.svc

但是当我去:

www.my域name.com/Service1.svc/test

www.my domain name.com/Service1.svc/test

我得到一个404错误。可能是什么原因?
这是所有相关的code:

I get a 404 error. What could be causing this? This is all relevant code:

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我需要做什么来适应服务器配置。

I suspect I made something wrong in the web.config. I'm very new to asp.net so it's possible I made any number of beginner mistakes. But because this works locally it could be something wrong with the configuration of the server I guess. Or something in the web.config I need to do to adapt to the server configuration.

感谢您阅读。

推荐答案

您必须添加到您的merhodTest接受behaviorto GET请求(默认情况下只接受POST)。要做到这一点添加WebInvoke行为它,例如通过添加以下属性以您的方式实施(这是一个行为)

You have to add to your merhodTest the behaviorto accept GET request (by default it accepts only POST). To do this add the WebInvoke behavior to it, for example by adding the following attribute to your method implementation (it's a behavior)

[WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json)]

顺便说一句,你可以删除的主机的从你的网络配置标签是不必要的。

btw you can remove the host tag from your web config it is unecessary

这篇关于部署服务器JSON WCF服务404的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆