gpt4 book ai didi

wcf - svcutil 不生成配置文件

转载 作者:行者123 更新时间:2023-12-04 11:29:39 28 4
gpt4 key购买 nike

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

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com