gpt4 book ai didi

WCF 3.5 在 IIS 中并行运行 SOAP 和 REST 服务

转载 作者:行者123 更新时间:2023-12-04 19:47:43 24 4
gpt4 key购买 nike

我知道这里有人问过类似的问题:

Running SOAP and RESTful on the same URL

Hosting WCF soap and rest endpoints side by side

但没有找到我的问题的答案。

我有两个启用依赖注入(inject)的自定义服务主机工厂:

public class StructureMapSoapServiceHostFactory : ServiceHostFactory 
public class StructureMapRestServiceHostFactory : WebServiceHost2Factory

实现细节在这里并不重要。

然后我在 web.config 中定义了两个端点

<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="mexGet">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="jsonBehavior">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<mexHttpBinding>
<binding name="mexHttpBinding" />
</mexHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="mexGet" name="ServiceImplementation.ServiceCategory">
<endpoint address="rest"
binding="webHttpBinding"
contract="Contracts.ServiceContracts.Mobile.IServiceCategory"
behaviorConfiguration ="jsonBehavior"/>
<endpoint address="soap"
binding="basicHttpBinding"
contract="Contracts.ServiceContracts.Mobile.IServiceCategory" />
<endpoint name="mexHttpBinding"
address="mex"
binding="mexHttpBinding" bindingConfiguration="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

然后我为每个自定义主机工厂创建了两个 .svc 文件:ServiceCategoryRest.svcServiceCategorySoap.svc

我不喜欢。我想做的是拥有那种风格的网址:

休息:http://server:port/rest/categories/ {id} 映射到我的 ServiceCategory.GetCategory(int id) 的实现

SOAP :http://server:port/soap/GetCategory?id=someId

我的问题是。我需要不同的 svc 文件来激活主机服务吗?如果我需要两个 .svc 文件,我怎样才能实现上面的 URI?恐怕我应该配置 IIS 重写或其他东西,但我想避免这种情况。

预先感谢您的帮助。

托马斯

最佳答案

您可以使用服务路由实现您想要的 - ASP.NET 路由的一部分,从 ASP.NET 3.5 SP1 开始可用。

查看这些资源:

在 .NET 3.5 SP1 中,您需要向 web.config 添加一些额外的基础结构(Web 路由模块等)——而在 .NET 4 中,这些都已内置。

关于WCF 3.5 在 IIS 中并行运行 SOAP 和 REST 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5705537/

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