WCF为REST POST调用生成帮助

时间:2011-06-05 10:15:00

标签: wcf rest

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

  

URL:   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);
}

1 个答案:

答案 0 :(得分:2)

您的DataContract怎么样?有没有FlagsAttribute的枚举?看来当你使用 [Flags] 时,WCF无法正确生成帮助页面。

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