【问题标题】:svcutil doesn't generate config filesvcutil 不生成配置文件
【发布时间】:2011-10-01 07:36:25
【问题描述】:

我有 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>

【问题讨论】:

    标签: wcf configuration svcutil.exe


    【解决方案1】:

    使用 WebHttpBinding(也称为 WCF WebHttp 端点)的端点不会像“普通”(即 SOAP)端点那样公开元数据。 WCF 仍会为您的服务生成 WSDL(因为您指定了&lt;serviceMetadata httpGetEnabled="true"/&gt;),但元数据将仅包含服务的某些方面(例如数据协定等)。与 Web 相关的功能(WebInvoke/WebGet 属性)不会在代理上,因此即使您获得代理文件,您也可能无法使用它与服务通信(除非您没有t 使用其中任何一个)。问题是没有广泛接受的格式来描述 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

    【讨论】:

    • 这不是真的。我尝试在家里制作简单的项目(在 VS2008,.NET 3.5 下)。服务端点配置了 webHttpBinding 和 webHttp 行为元素。命令 svcutil.exe localhost:3065/Service1.svc?wsdl 得到了代理和配置文件。
    • 检查配置文件中使用的绑定 - 它不会是 webHttpBinding。您可能在服务上遇到了一些默认端点。
    • 服务只有一个端点。 svcutil 为可以通过 SOAP 访问端点的客户端(customBinding 的 textMessageEncoding 的 messageVersion="Soap12")奠定了基础。并且在配置文件中有描述。第一个样品根本没有。
    • svcutil 创建的不是一个等效于 webHttpBinding 的绑定(webHttpBinding 没有 SOAP 版本,等效于 messageVersion.None)。 svcutil 正在为服务上存在的另一个端点创建客户端配置,而不是具有 webHttpBinding/webHttp 行为的一个端点。 WebHttpBinding 端点没有暴露在 svcutil 使用的 WSDL/元数据中。
    • @carlosfigueira 如果 svcutil 无法创建 .config,我该如何利用 app.config 才能找到 wcf 的端点?我得到的错误:找不到引用合同的默认端点元素.....问候
    猜你喜欢
    • 2022-10-19
    • 2011-02-09
    • 2020-09-22
    • 1970-01-01
    • 2018-03-26
    • 1970-01-01
    • 1970-01-01
    • 2011-05-17
    相关资源
    最近更新 更多