【问题标题】:Server Error in '/' Application when I am running the simple method in WCF Service当我在 WCF 服务中运行简单方法时,“/”应用程序中的服务器错误
【发布时间】:2019-12-04 08:00:01
【问题描述】:

[当我在 u-r-l 中添加方法测试时,它显示服务器应用程序中的错误] [这是我的 W.C.F 服务中的内容,我正在尝试查看方法测试][3]

    public string test()
    {
        // Add your operation implementation here
        return "test...";
    }

下面是错误 https://i.stack.imgur.com/EdFt9.png

【问题讨论】:

  • 请不要在问题中插入您的代码图片。将代码作为文本插入,以便更轻松地为您提供帮助
  • localhost:44305/Service/Service1.svc/test(当我在 url 中添加测试时,它显示服务器应用程序出错)

标签: asp.net wcf


【解决方案1】:

如果你想在浏览器中直接访问你的WCF操作,可以参考下面的配置。
Service Contract.

    public interface IService1
    {
        [OperationContract]
        [WebGet]
        string GetData(int value);
}

Service.svc

public string GetData(int value)
        {
            return DateTime.Now.ToLongTimeString();
        }

Web 配置,只需替换 System.servicemodel 部分即可。

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior>
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="webHttpBinding" scheme="http" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  </system.serviceModel>

结果。

有关如何创建基本 WCF Web HTTP 服务的更多详细信息。
https://docs.microsoft.com/en-us/dotnet/framework/wcf/feature-details/how-to-create-a-basic-wcf-web-http-service
如果有什么可以帮助的,请随时告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-07
    • 2021-05-09
    • 2017-09-18
    • 2014-07-31
    • 1970-01-01
    • 2021-11-21
    相关资源
    最近更新 更多