我最近将WCF SOAP服务转换为REST/JSON服务。如响应here中所述,Visual Studio的“添加服务引用”功能无法为JSON服务生成代码。在这个问题的答案中的链接文章暗示有一个WCF作为REST和SOAP公开的可能性来解决这个问题,但它没有给出任何细节如何这样做。JSON和SOAP WCF服务?
有谁知道这是否可能,如果是这样,如何设置它?
自己编写代码生成器总是有其他选择,它读取WCF REST服务的WSDL并生成C#类,但似乎应该有比这更容易的解决方案。
仅供参考, 我的web.config:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="RestBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
<serviceBehaviors>
<behavior name="GetBehavior" >
<serviceMetadata httpGetEnabled="true" />
<serviceDebug
httpHelpPageEnabled="true"
includeExceptionDetailInFaults="true"
/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<webHttpBinding>
<binding name="WebHttpBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service name="Service" behaviorConfiguration="GetBehavior">
<endpoint address=""
binding="webHttpBinding"
behaviorConfiguration="RestBehavior"
contract="IService"
bindingConfiguration="WebHttpBinding">
</endpoint>
</service>
</services>
</system.serviceModel>
我的服务方法都具有以下属性:
[WebInvoke(RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped)]
客户端和服务解决方案是否可以共享相同的“Models”项目? (Models == DataContracts) – lcryder