wcf - svcutil 不生成配置文件

标签 wcf configuration svcutil.exe

我有 wcf 服务。我尝试通过 svcutil 为客户端程序生成代理代码和配置文件:

svcutil http://localhost/WcfService2/Files.svc

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

我的服务契约(Contract):
[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>

最佳答案

使用 WebHttpBinding 的端点(也称为 WCF WebHttp 端点)不会像“普通”(即 SOAP)端点那样公开元数据。 WCF 仍会为您的服务生成 WSDL(因为您指定了 <serviceMetadata httpGetEnabled="true"/> ),但元数据将只包含服务的某些方面(例如数据契约(Contract)等)。与 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

关于wcf - svcutil 不生成配置文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6625525/

相关文章:

.net - 执行时出现简单 WCF 服务错误

javascript - 关于将大字符串发布到 Web 服务的建议

c# - 在 Asp.Net MVC 应用程序中调用 wcf 服务

wpf - 取消异步 WCF 请求的最佳方法是什么?

configuration - 无法编辑 Sublime Text 的默认设置

soap - 如何连接到 SVC 端点?

.net - 如何确定要在我的 svcutil 命令行中包含哪些架构文件 (xsd)?

java - PropertySourcesPlaceholderConfigurer 和 SpEL?

c - SIMULINK 保持信号的先前值

svcutil.exe - 如果我传递/引用参数,为什么 SvcUtil.exe 不会生成 References.cs?