【发布时间】:2011-04-18 15:51:31
【问题描述】:
我知道这里有人问过类似的问题:
Running SOAP and RESTful on the same URL
Hosting WCF soap and rest endpoints side by side
但没有找到我的问题的答案。
我有两个启用依赖注入的自定义服务主机工厂:
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.svc ServiceCategorySoap.svc
我不喜欢它。我想做的是拥有那种风格的网址:
REST : http://server:port/rest/categories/{id} 映射到我的 ServiceCategory.GetCategory(int id) 的实现
SOAP:http://server:port/soap/GetCategory?id=someId
我的问题是。我需要不同的 svc 文件来激活主机服务吗?如果我需要两个 .svc 文件,如何实现上面的 URI?恐怕我应该配置 IIS 重写或其他东西,但想避免这种情况。
提前感谢您的帮助。
托马斯
【问题讨论】: