【发布时间】:2018-10-14 16:03:38
【问题描述】:
我在 VS2017 中有一个非常简单的 WCF 服务项目。但是当我尝试访问端点时,我不断收到错误 400。我已阅读此处发布的有关同一问题的其他问题,但到目前为止我已经尝试过,但没有成功。
我的服务合同:
[ServiceContract]
public interface IService
{
[OperationContract]
[WebInvoke(Method = "GET",
BodyStyle = WebMessageBodyStyle.Wrapped,
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/GetData/{value}")]
string GetData(string value);
}
我的服务:
public class Service : IService
{
public string GetData(string value)
{
return string.Format("You entered: {0}", value);
}
}
我的网络配置:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="myBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
<behavior name="">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="myBehavior" name="WCGFService1.Service">
<endpoint address="" contract="WCGFService1.IService" binding="webHttpBinding">
</endpoint>
</service>
</services>
当我访问 http://localhost:61648/Service.svc/GetData/12 时,我收到 HTTP 400 错误请求。我试过浏览器和邮递员。我做错了什么?
我正在使用 VS2017。我的 IService.cs 和 Service.cs 位于 App_Code 文件夹中,而
Service.svc 位于根文件夹中。另外,当我尝试在 web.config 中添加 name 和 contract 时,VS2013 会建议我命名空间和接口/类名,而 VS2017 并没有建议我任何东西,所以我必须手动输入。
另外,在 VS2013 中,接口和类位于根文件夹中,而不是 App_Code 文件夹中。该项目是VS2017中的WCF应用程序。我的 .NET 版本是 4.5.2。
【问题讨论】:
标签: wcf