WCF REST服务没有响应并发出500错误

时间:2017-05-09 23:59:36

标签: c# asp.net web-services rest wcf

我尝试在现有的ASP.NET应用程序中创建WCF REST服务。但是,当我尝试使用网络浏览器浏览我的服务时,它表示"此网站无法访问"。

我想点击的网址是:http://localhost:81/ExternalServices/WS/Snap/REST/SnapService.svc

另外,当我尝试使用客户端工具点击它时,它会给出错误500。

// SnapService.svc
<% @ServiceHost Service = "DomainName.ProjectName.WebApp.ExternalServices.WS.Snap.REST.SnapService" Language="C#" %>

// ISnapService.cs
namespace DomainName.ProjectName.WebApp.ExternalServices.WS.Snap.REST
{
    [ServiceContract]
    public interface ISnapService
    {
        [OperationContract]
        [WebInvoke(Method = "POST", UriTemplate = "UpdateLender")]
        string UpdateLender(string userName, string password, string portfolioCode, string xmlRequest);
    }
}

// SnapService.cs
namespace DomainName.ProjectName.WebApp.ExternalServices.WS.Snap.REST
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class SnapService : ISnapService
    {
        public string UpdateLender(string userName, string password, string portfolioCode, string xmlRequest)
        {
            // implementation here
            return SnapServiceHelper.UpdateLender(userName, password, portfolioCode, xmlRequest);
        }
    }
}

// Web.config
  <system.serviceModel>
    <services>
        <service name="DomainName.ProjectName.WebApp.ExternalServices.WS.Snap.REST.SnapService" behaviorConfiguration="defaultBehaviour">
        <endpoint name="webHttpsBinding" address="" binding="webHttpBinding" contract="DomainName.ProjectName.WebApp.ExternalServices.WS.Snap.REST.ISnapService" behaviorConfiguration="webHttp" bindingConfiguration="webHttpTransportSecurity"/>
        <endpoint name="mexHttpsBinding" address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="webHttpTransportSecurity">
          <security mode="Transport"/>
        </binding>
      </webHttpBinding>
    </bindings>
    <behaviors>
      <endpointBehaviors>
        <behavior name="webHttp">
          <webHttp helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="defaultBehaviour">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>

编辑:启用调试以写入日志文件。这是我尝试浏览上述链接时遇到的异常:

Operation&#39; UpdateLender&#39;合同&#39; ISnapService&#39;指定要序列化的多个请求正文参数,而不包含任何包装元素。最多可以在没有包装元素的情况下序列化一个body参数。删除额外的body参数或将WebGetAttribute / WebInvokeAttribute上的BodyStyle属性设置为Wrapped。

0 个答案:

没有答案