【问题标题】:WCF Generate help for REST POST callWCF 为 REST POST 调用生成帮助
【发布时间】:2011-09-08 16:40:31
【问题描述】:

使用 WCF,可以为 webHTTPBinding 生成帮助。使用 WebGet 操作,它就像魅力一样。但是,使用 WebInvoke (Method = "POST") 并没有给我任何帮助。在页面中我可以看到:

网址: http://localhost/edumatic3/trunk/services/service.svc/rest/saveUser

HTTP 方法:POST

消息方向格式正文

请求未知无法生成架构文档。

响应未知 无法生成架构文档。

有什么想法吗?

Web.Config system.serviceModel

<system.serviceModel>
  <bindings>
    <basicHttpBinding>
      <binding name="basicHttpBindingConfiguration">
        <security mode="TransportWithMessageCredential" />
      </binding>
    </basicHttpBinding>
  </bindings>
  <behaviors>
    <endpointBehaviors>
      <behavior name="HelpEndPointBehavior">
        <webHttp helpEnabled="true" automaticFormatSelectionEnabled="false" />
      </behavior>
    </endpointBehaviors>
    <serviceBehaviors>
      <behavior name="ServiceBehavior">
        <serviceMetadata httpGetEnabled="true" />
        <serviceDebug includeExceptionDetailInFaults="true" />
        <serviceCredentials>
          <userNameAuthentication userNamePasswordValidationMode="Custom"
           customUserNamePasswordValidatorType=      
           "Edu3.Service.OpenApi.Security.CustomUserNameValidator
           , Edu3.Service.OpenApi" />
        </serviceCredentials>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <services>
    <service name="OpenApiService" 
             behaviorConfiguration="ServiceBehavior">
    <endpoint name="soap" 
              address="soap" 
              binding="basicHttpBinding" 
              contract="Edu3.Service.OpenApi.Interface.IService" 
              bindingConfiguration="basicHttpBindingConfiguration"/>
    <endpoint name="rest" 
              address="rest" 
              behaviorConfiguration="HelpEndPointBehavior"      
              binding="webHttpBinding" 
              contract="Edu3.Service.OpenApi.Interface.IService"/>
    <endpoint name="mex"  
              address="mex" 
              binding="mexHttpBinding" 
              contract="IMetadataExchange" />
  </service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"  
                           multipleSiteBindingsEnabled="true">
  <serviceActivations>
    <add relativeAddress="services/service.svc" 
         service="OpenApiService" 
         factory="Spring.ServiceModel.Activation.ServiceHostFactory"/>
  </serviceActivations>
</serviceHostingEnvironment>

服务合同: GetNodeByKey 给了我明确的帮助。 SaveUser 不是。

[ServiceContract]
public interface IService
{
    [OperationContract]
    [WebGet(UriTemplate = "login?userName={userName}&password={password}")]
    void Login(string userName, string password);


    [OperationContract]
    [WebGet(UriTemplate = "getNodeByKey/{key}?getAllDescendants={getAllDescendants}"
        , ResponseFormat = WebMessageFormat.Json)]
    [ServiceKnownType(typeof(BranchNodeDTO))]
    [ServiceKnownType(typeof(LeafNodeDTO))]
    [ServiceKnownType(typeof(CasusNodeDTO))]
    [ServiceKnownType(typeof(BucketNodeDTO))]
    NodeDTO GetNodeByKey(string key, string getAllDescendants);

    [OperationContract]
    [WebInvoke(UriTemplate = "saveUser", Method = "POST"
        , BodyStyle = WebMessageBodyStyle.WrappedRequest)]
    UserDto SaveUser(UserDto user, int channelId);
}

【问题讨论】:

  • 请求和响应的操作和数据合同是什么样的?
  • 我已经用 system.serviceModel 和 ServiceContract 编辑了这个问题。
  • 如果从SaveUser 中删除channelId(仅用于测试)并制作正文样式Bare,它会起作用吗?

标签: wcf rest


【解决方案1】:

你的 DataContract 怎么样?是否有任何具有 FlagsAttribute 的枚举?当您使用 [Flags] 时,WCF 似乎无法正确生成帮助页面。

来源: http://support.microsoft.com/kb/2020406/en-us

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-28
    相关资源
    最近更新 更多