gpt4 book ai didi

c# - basicHttpBinding 和 webHttpBinding 在一起

转载 作者:太空狗 更新时间:2023-10-29 22:52:47 27 4
gpt4 key购买 nike

我正在使用 C# 和 .NET Framework 4.0 开发 WCF 服务。

我正在使用 webHttpBinding 来执行此操作:

[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "filteredOrders/")]
OrderContract[] GetOrders(IdsMessage msg);

[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Bare,
UriTemplate = "completeFilteredOrders/")]
OrderContract[] LoadCompleteFilteredOrders(IdsMessage msg);

但现在我需要使用流传输将图像发送到该 Web 服务,并且我需要添加 basicHttpBinding 来完成它。

我如何为这个使用 basicHttpBinding 的 WCF Web 服务创建一个新的 [OperationContract]

抱歉,我对 WCF 开发还很陌生。

顺便说一句,这是我的Web.config:

<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="EReportService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="EReportService.IRestServiceImpl" behaviorConfiguration="web">
</endpoint>
</service>
</services>
<bindings>
<webHttpBinding>
<binding maxReceivedMessageSize="2097152" maxBufferSize="2097152" transferMode="Streamed"/>
</webHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviour">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
<connectionStrings>

</connectionStrings>
</configuration>

最佳答案

只需使用不同的地址创建另一个端点(两个端点不能共享相同的地址)- 您可以修改现有的 OperationContract 以创建非 RESTful 方法。

 <system.serviceModel>
<services>
<service name="EReportService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
<endpoint address="" binding="webHttpBinding" contract="EReportService.IRestServiceImpl" behaviorConfiguration="web">
</endpoint>
<endpoint address="soap" binding="basicHttpBinding" contract="EReportService.IRestServiceImpl" >
</endpoint>
</service>
</services>
</system.serviceModel>

关于c# - basicHttpBinding 和 webHttpBinding 在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13611928/

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