在同一WCF服务和契约上启用SOAP和REST
我有一个带有basichttpbinding的现有WCFSOAP服务。现在,我想扩展它,使其具有一个只包含rest属性的多个契约,这样现有的方法就不会影响使用此契约的客户机 粘贴服务中的一些主要代码片段(不包括不必要的代码),如果您需要什么,请告诉我:在同一WCF服务和契约上启用SOAP和REST,wcf,wcf-binding,wcf-rest,Wcf,Wcf Binding,Wcf Rest,我有一个带有basichttpbinding的现有WCFSOAP服务。现在,我想扩展它,使其具有一个只包含rest属性的多个契约,这样现有的方法就不会影响使用此契约的客户机 粘贴服务中的一些主要代码片段(不包括不必要的代码),如果您需要什么,请告诉我: public interface IMessages { // existing contract [OperationContract(Name = "LoadMessage", IsOneWay = t
public interface IMessages
{
// existing contract
[OperationContract(Name = "LoadMessage", IsOneWay = true)]
void LoadMessage(Guid categoryId, int fileId);
// new REST contract
[WebInvoke(Method = "POST",
UriTemplate = "/LoadMessagesApi/{param}",
ResponseFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.Wrapped)]
[Description("Inbound Message")]
void LoadMessagesApi(string param);
}
公共接口IPayment:IMessages
{
}
配置:
<service name="Services.PaymentService">
<endpoint address="xmlservice"
binding="webHttpBinding"
behaviorConfiguration="RestBehavior"
contract="Services.Interfaces.IPayment""/>
<endpoint address="" binding="wsHttpBinding"
bindingConfiguration="wsHttpBindingConfig"
name="httpGateway"
contract="Services.Interfaces.IPayment" />
</service>
<behaviors>
<serviceBehaviors>
<behavior name="RestBehavior">
<!--Behaviour for REST endpoint for HELP enability-->
<webHttp helpEnabled ="true"></webHttp>
</behavior>
</endpointBehaviors>
</behaviors>
您的服务接口有问题。在ServiceContract中,如果其中一个方法使用WebInvoke,则其他方法需要使用WebInvoke或webget,因此解决方案是将WebInvoke或webget添加到LoadMessage,或将LoadMessagesApi上方的WebInvoke修改为OperationContract。您的服务接口有问题。在ServiceContract中,如果其中一个方法使用WebInvoke,则其他方法需要使用WebInvoke或webget,因此解决方案是将WebInvoke或webget添加到LoadMessage,或将LoadMessagesApi上方的WebInvoke修改为OperationContract.OK,这解决了此问题。您可以添加一个答案,我将其标记为答案,谢谢