WCF Rest方法/操作未找到 - 一切似乎都配置正确

问题描述 投票:0回答:1

我已经在此链接后创建了一个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>

c# json rest wcf
1个回答
0
投票

我从Web.config中删除了以下设置中的问题。

因为我也在我的本地IIS中运行它不仅在IIS express中。这些设置可能是由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>

我认为问题只是“<directoryBrowse enabled =”false“/>”,但实际上是“<handlers> ... </ handlers>”。

© www.soinside.com 2019 - 2024. All rights reserved.