【发布时间】:2014-08-14 17:59:04
【问题描述】:
这是默认向导在 Visual Studio 2013 中创建的代码。 在项目属性中,我设置为使用本地 IIS。 WCF 测试客户端测试成功。 但是如果我访问页面
http://localhost/WcfService1/Service1.svc/GetTime
在浏览器中,我看到空的浏览器屏幕,Fiddler 显示“HTTP/1.1 400 Bad Request”。 我知道我需要修改 web.config,以及接口中方法的属性,但不知道如何。你可以帮帮我吗?谢谢。
IService1.cs
using System.Runtime.Serialization;
using System.ServiceModel;
namespace WcfService1
{
[ServiceContract]
public interface IService1
{
[OperationContract]
string GetTime();
}
}
Service1.svc.cs
using System;
namespace WcfService1
{
public class Service1 : IService1
{
public string GetTime()
{
return DateTime.Now.ToShortTimeString();
}
}
}
web.config
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
【问题讨论】:
-
你需要在 web.config 中描述端点
-
你有一个 SOAP 服务。您正试图像 REST 服务一样访问它,但您不能这样做。您需要代理才能使用 SOAP 服务 - 您不能直接在浏览器中调用方法。