0

我正在尝试将对象参数作为 JSON 格式传递给 WCF restful 服务。

像这样的服务合同代码;

 [OperationContract]
 [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Xml, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "xml/{id}")]
 string XMLData(string ID);

我的 web.config 文件是这样的;

<system.serviceModel>
<services>
  <service name="RestService.RestServiceImpl" behaviorConfiguration="ServiceBehaviour">
    <endpoint address="" binding="webHttpBinding" contract="RestService.IRestServiceImpl" behaviorConfiguration="web">
    </endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="ServiceBehaviour">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<protocolMapping>
  <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />

当我尝试使用“ http://localhost/serviceurl/xml/123 ” url 调用服务时,服务返回“方法不允许”错误消息。

4

1 回答 1

0

我解决了。我不得不从文件中删除<ProtocolMapping>and<ServiceHostingEnvironment>标记。web.config

它现在工作正常。

于 2017-02-16T14:14:13.807 回答