[英]WCF 3.5 running SOAP and REST services side by side in IIS
我知道这里有类似的问题:
但没有找到我的问题的答案。
我有两个自定义servicehostfactories启用依赖注入:
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
我不喜欢它。 我想做的是拥有该样式的URL:
REST: 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中,这些都已内置。
经过几次搜索,我发现实际上我不需要两个不同的.svc文件和两个不同的ServiceHostFactories。
我只保留了StructureMapRestServiceHostFactory:WebServiceHost2Factory和ServiceCategoryRest.svc,它在REST模式下处理井请求并在RPC-SOAP模式下调用。
因此,如果您希望并行运行REST和SOAP,则只能使用WebServiceHost2Factory。
如果您想要从URL中删除.svc部分,请阅读Rick Strahl帖子west-wind.com/weblog/posts/570695.aspx。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.