405路由WCF服务时不允许的方法

时间:2014-10-16 15:05:23

标签: c# wcf

每当我尝试浏览服务时,我都会收到错误 - 方法不允许。 如果我尝试运行svcutil后跟服务URL,那么我得到同样的错误 - 请求失败,HTTP状态为405:Method Not Allowed。

我已经在webconfig文件中进行了必要的更改,但仍面临同样的问题。

Webconfig 1

<system.serviceModel>
<services>          
<service name="MyService">
    <endpoint address="http://localhost:55924/ACT" binding="wsHttpBinding" contract="ACT.Services" />               
    <endpoint address="http://localhost/MyService/mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<bindings>
<basicHttpBinding>
    <binding name="" maxReceivedMessageSize="262144"></binding>
</basicHttpBinding>
</bindings>     
<protocolMapping>
<add scheme="http" binding="webHttpBinding"/>
</protocolMapping>      
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>           
    <standardEndpoint name="" helpEnabled="true" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
<behaviors>
<serviceBehaviors>
    <behavior name="">
        <serviceMetadata httpGetEnabled="true" policyVersion="Policy12"/>
        <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>             
</serviceBehaviors>
<endpointBehaviors>
    <behavior>
        <webHttp />
    </behavior >
</endpointBehaviors>
</behaviors>
</system.serviceModel>

的Global.asax.cs

public class Global : HttpApplication
   {
        void Application_Start(object sender, EventArgs e)
        {
           RegisterRoutes();
        }

    private void RegisterRoutes()
    {
        // Edit the base address of Service1 by replacing the "Service1" string below
        RouteTable.Routes.Add(new ServiceRoute("", new WebServiceHostFactory(), typeof(ACTServices)));
    }
}

的ServiceContract

namespace ACT
  {
       [ServiceContract]
       [AspNetCompatibilityRequirements(RequirementsMode =  AspNetCompatibilityRequirementsMode.Allowed)]
       [ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall)]
    public class ACTServices
    {


    [OperationContract]
    [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, UriTemplate = "GetUserData", RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
    [FaultContract(typeof(ExceptionHandler))]
    public List<UserData> GetUser(UserSearchCode searchcode)
    {
        try
        {

            return objRetrieveData.GetUserfromACT(searchcode.firstName, searchcode.lastName);
        }
        catch (Exception e)
        {
            ExceptionHandler eH = new ExceptionHandler();
            eH.status = "Error";
            eH.message = e.Message;
            throw new WebFaultException<ExceptionHandler>(eH, HttpStatusCode.InternalServerError);
        }
        //return new List<UserData>();
    }

  }
}

你能否提出我缺少的其他配置?

0 个答案:

没有答案