svcutil不生成配置文件 [英] svcutil does't generate config file

查看:175
本文介绍了svcutil不生成配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have wcf service. I tried to generate proxy code and configuration file for client program by svcutil:

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



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

I got valid file with proxy, but didn't get config file. Why? (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>


推荐答案

使用WebHttpBinding(aka,WCF WebHttp endpoints ),不要公开诸如正常(即SOAP)端点的元数据。 WCF仍然会为你的服务生成一个WSDL(因为你指定了< serviceMetadata httpGetEnabled =true/> ),但是元数据只包含服务的某些方面(如数据合同等)。 Web相关的功能(WebInvoke / WebGet属性)不会在代理上,所以即使你得到一个代理文件,你可能将无法使用它来与服务通信(除非你没有使用任何这些)。问题是没有广泛接受的用于描述REST服务的元数据的格式(WADL可能是最常用的,但是它不像SOAP的WSDL那么普遍,并且它不是由WCF实现的)。

Endpoints which use the WebHttpBinding (a.k.a., WCF WebHttp endpoints), do not expose metadata like "normal" (i.e., SOAP) endpoints do. WCF will still generate a WSDL for your service (since you specified <serviceMetadata httpGetEnabled="true"/>), but the metadata will only contain certain aspects of the service (such as data contracts, etc). The Web-related features (WebInvoke/WebGet attributes) won't be on the proxy, so even though you get a proxy file, you'll likely won't be able to use it to communicate to the service (unless you didn't use any of those). The problem is that there's no widely accepted format for describing metadata for REST services (WADL is possibly the most used, but it's not nearly as prevalent as WSDL for SOAP, and it's not implemented by WCF).

简而言之:svcutil对于Web端点不起作用。

In short: svcutil doesn't really work for web endpoints.

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

这篇关于svcutil不生成配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆