开发者

WCF Generate help for REST POST call

开发者 https://www.devze.com 2023-03-11 15:38 出处:网络
Using WCF, it is possible to generate help for a webHTTPBinding. With a WebGet operation, it works like charm. Using a WebInvoke (Method = \"POST\") however doesn\'t give me any help. In the pages I c

Using WCF, it is possible to generate help for a webHTTPBinding. With a WebGet operation, it works like charm. Using a WebInvoke (Method = "POST") however doesn't give me any help. In the pages I can see this:

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

HTTP Method: POST

Message direction Format Body

Request开发者_运维百科 Unknown Could not generate schema document.

Response Unknown Could not generate schema document.

Any ideas?

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>

Service Contract: The GetNodeByKey gives me clear help. The SaveUser not.

[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);
}


What about your DataContract? Are there any enums which have FlagsAttribute? It seems that when you use [Flags] WCF isn't able to correctly generate the help page.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号