svcutil不生成配置文件

时间:2011-07-08 13:59:25

标签: wcf configuration svcutil.exe

我有wcf服务。我试图通过svcutil:

为客户端程序生成代理代码和配置文件
svcutil http://localhost/WcfService2/Files.svc

我使用代理获得了有效文件,但没有获得配置文件。为什么? (VS2010 SP1,.NET 4.0,IIS 7.0)

我的服务合同:

[ServiceContract]
public interface IFiles
{
    [OperationContract]
    Guid UploadFile(Stream stream);
}

我的网络配置:

<?xml version="1.0"?>
<configuration>

  <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding name="WebHttpBinding" maxBufferSize="65536" maxBufferPoolSize="524288"
          maxReceivedMessageSize="1073741824" transferMode="Streamed" />
      </webHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="MyServiceBehavior" name="WcfService2.Files">
        <endpoint behaviorConfiguration="WebHttpBehavior" binding="webHttpBinding"
          bindingConfiguration="WebHttpBinding" name="Files" contract="WcfService2.IFiles" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="WebHttpBehavior">
          <webHttp defaultBodyStyle="Wrapped" defaultOutgoingResponseFormat="Json"
            automaticFormatSelectionEnabled="false" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="MyServiceBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
  <system.web>
    <httpRuntime maxRequestLength="100000" />
  </system.web>

</configuration>

1 个答案:

答案 0 :(得分:9)

使用WebHttpBinding(a.k.a。,WCF WebHttp端点)的端点不会像“普通”(即SOAP)端点那样公开元数据。 WCF仍将为您的服务生成WSDL(因为您指定了<serviceMetadata httpGetEnabled="true"/>),但元数据将仅包含服务的某些方面(例如数据协定等)。与Web相关的功能(WebInvoke / WebGet属性)将不在代理上,因此即使您获得代理文件,您也可能无法使用它与服务进行通信(除非您没有'使用其中任何一个)。问题在于,没有广泛接受的格式来描述REST服务的元数据(WADL可能是最常用的,但它并不像SOAP的WSDL那样流行,而且它不是由WCF实现的。)

简而言之:svcutil并不适用于Web端点。

如果您想要长版:http://blogs.msdn.com/b/carlosfigueira/archive/2012/03/26/mixing-add-service-reference-and-wcf-web-http-a-k-a-rest-endpoint-does-not-work.aspx

相关问题