找不到WCF休息方法/操作 - 似乎所有内容都配置正确

时间:2018-01-02 15:53:34

标签: c# json rest wcf

我在此链接后创建了一个WCF Rest,但它对我不起作用。 我的项目已经有了另一个标准WCF服务。

http://dotnetmentors.com/wcf/wcf-rest-service-to-get-or-post-json-data-and-retrieve-json-data-with-datacontract.aspx

浏览器正确显示WSDL,但我正在尝试进行GET或POST调用,而我只获得404.

请注意,我有1个POST和其他GET方法,两者都不起作用。

网址:http://silos:8085/KdtCustomerInterfaceRest.svc/CreateWooCommerceProduct

这是我的所有代码。

IKDTCustomerInterfaceRest.svc.cs

 [ServiceContract]
public interface IKDTCustomerInterfaceRest
{
    [OperationContract]
    [WebInvoke(BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "/CreateWooCommerceProduct",
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json, Method = "POST")]
    bool CreateWooCommerceProduct(string key, PriceBookEntry productItem);

    [OperationContract]
    [WebGet(UriTemplate = "/OrderId/{OrderID}",
        ResponseFormat = WebMessageFormat.Json)]
    string OrderId(string OrderID);
}

IKDTCustomerInterfaceRest.svc

public class KDTCustomerInterfaceRest : IKDTCustomerInterfaceRest
    {
        [WebInvoke(BodyStyle = WebMessageBodyStyle.Wrapped)]
        public bool CreateWooCommerceProduct(string key, PriceBookEntry productItem)
        {
            using (var manager = new OrderProcessing())
            {
                var result = manager.UpdateWooCommerceProducts(key ,productItem);
                return result.IsSuccess;
            }
        }

        public string OrderId(string OrderID)
        {
            return OrderID;
        }
}

的Web.Config

 <system.serviceModel>

<bindings>
  <basicHttpBinding>
    <binding name="BasicHttpBinding_IKDService" />
  </basicHttpBinding>
</bindings>
<client>
  <endpoint address="http://kdwebservices9.kingdevicktest.com/KDService.svc/soap"
    binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IKDService"
    contract="KDService.IKDService" name="BasicHttpBinding_IKDService" />
</client>
<behaviors>
  <endpointBehaviors>
    <behavior name="webBehavior">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false" />
    </behavior>
    <!--<behavior name="MyServiceBehavior"  returnUnknownExceptionsAsFaults="True">-->  
    <!--</behavior>-->  
  </serviceBehaviors>
</behaviors>
<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>    
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
  <service name="KdtCostumerInterface.KdtCostumerInterfaceService">
    <endpoint address="" binding="basicHttpBinding" contract="KdtCostumerInterface.IKdtCostumerInterfaceService">
      <identity>
        <dns value="localhost" />
      </identity>
    </endpoint>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:8085/KD.CostumerInterface.API/" />
      </baseAddresses>
    </host>
  </service>
  <service name="KdtCostumerInterface.KDTCustomerInterfaceRest">
    <endpoint address="" behaviorConfiguration="webBehavior" binding="webHttpBinding" contract="KdtCostumerInterface.IKDTCustomerInterfaceRest" />
    <!--<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />-->
  </service>
</services>

1 个答案:

答案 0 :(得分:0)

我对从Web.config中删除以下设置的问题进行了排序。

因为我也在IIS本地IIS中运行它。 这些设置可能是由IIS添加的。

<directoryBrowse enabled="false" />
    <handlers>
      <remove name="svc-Integrated-4.0" />
      <add name="svc-Integrated-4.0" path="*" verb="*" type="System.ServiceModel.Activation.ServiceHttpHandlerFactory, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" resourceType="Unspecified" requireAccess="Script" preCondition="integratedMode,runtimeVersionv4.0" />
    </handlers>

我认为问题只是&#34;&lt; directoryBrowse enabled =&#34; false&#34; /&GT;&#34;但实际上是&#34;&lt;处理程序&GT; ...&LT; /处理程序&GT;&#34;