【发布时间】:2012-10-26 11:23:38
【问题描述】:
我有一个包含大约 100 个函数的 WCF SOAP 服务。我只想将其中一些暴露给 REST 端点。难道只有一份合同就可以做到这一点吗?
我添加了这样的休息行为和休息端点:
<behaviors>
<endpointBehaviors>
<behavior name="RestBehavior">
<webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json"/>
</behavior>
</endpointBehaviors>
</behaviors>
<endpoint address="json" binding="webHttpBinding" behaviorConfiguration ="RestBehavior" contract="Test.IService" />
<endpoint address="" binding="customBinding" bindingConfiguration="BufferedHttpBinaryBusiness"
bindingName="BufferedHttpBinaryBusiness" contract="Test.IService" />
并将WebGet 属性添加到我想在休息端点上公开的函数中:
<WebGet(BodyStyle:=WebMessageBodyStyle.Wrapped, RequestFormat:=WebMessageFormat.Json, ResponseFormat:=WebMessageFormat.Json, UriTemplate:="/IsRegistered?Id={Id}")>
<ServiceModel.OperationContract()>
Function IsRegistered(ByVal Id As String) As Boolean
但我也有我不想公开为 REST 的其他功能。
<ServiceModel.OperationContract()>
Function GetName(ByVal x As Long, ByVal y As String) As String
<ServiceModel.OperationContract()>
Function GetId(ByVal name As String) As String
我得到的错误是:
System.InvalidOperationException: Operation 'GetName' of contract 'IService' specifies multiple request body parameters to be serialized without any wrapper elements. At most one body parameter can be serialized without wrapper elements. Either remove the extra body parameters or set the BodyStyle property on the WebGetAttribute/WebInvokeAttribute to Wrapped.
at System.ServiceModel.Description.WebHttpBehavior.TryGetNonMessageParameterType(MessageDescription message, OperationDescription declaringOperation, Boolean isRequest, Type& type)
at System.ServiceModel.Description.WebHttpBehavior.ValidateBodyStyle(OperationDescription operation, Boolean request)
at System.ServiceModel.Description.WebHttpBehavior.<>c__DisplayClass10.<>c__DisplayClass13.<GetRequestDispatchFormatter>b__d()
at System.ServiceModel.Description.WebHttpBehavior.<>c__DisplayClass10.<GetRequestDispatchFormatter>b__c()
at System.ServiceModel.Description.WebHttpBehavior.HideReplyMessage(OperationDescription operationDescription, Effect effect)
at System.ServiceModel.Description.WebHttpBehavior.GetRequestDispatchFormatter(OperationDescription operationDescription, ServiceEndpoint endpoint)
at System.ServiceModel.Description.WebHttpBehavior.ApplyDispatchBehavior(ServiceEndpoint endpoint, EndpointDispatcher endpointDispatcher)
at System.ServiceModel.Description.DispatcherBuilder.InitializeServiceHost(ServiceDescription description, ServiceHostBase serviceHost)
at System.ServiceModel.ServiceHostBase.InitializeRuntime()
at System.ServiceModel.ServiceHostBase.OnOpen(TimeSpan timeout)
at System.ServiceModel.Channels.CommunicationObject.Open(TimeSpan timeout)
at Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo info)
当我向这个函数添加 WebGet 属性时,另一个肥皂函数会发生同样的错误。似乎它需要我将 WebGet 属性应用于所有函数。换句话说,它要求我公开合约中的所有函数以公开给 REST 端点。但我只希望其中一些以 REST 形式出现。不可能吗?
【问题讨论】:
标签: wcf rest soap behavior endpoint