Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery 具有共享主机的WCF服务导致404(放置在IIS应用程序中)_Jquery_Wcf_Iis 7_Http Post_Wcf Configuration - Fatal编程技术网

Jquery 具有共享主机的WCF服务导致404(放置在IIS应用程序中)

Jquery 具有共享主机的WCF服务导致404(放置在IIS应用程序中),jquery,wcf,iis-7,http-post,wcf-configuration,Jquery,Wcf,Iis 7,Http Post,Wcf Configuration,如果我尝试使用jQuery或通过浏览器点击一个方法,我会得到一个404。我的配置如下所示: <system.serviceModel> <behaviors> <serviceBehaviors> <behavior name="RegistrationBehavior"> <serviceMetadata httpGetEnabled="true" />

如果我尝试使用jQuery或通过浏览器点击一个方法,我会得到一个404。我的配置如下所示:

<system.serviceModel>
    <behaviors>
        <serviceBehaviors>
            <behavior name="RegistrationBehavior">
                <serviceMetadata httpGetEnabled="true" />
                <serviceDebug includeExceptionDetailInFaults="true" />
            </behavior>
        </serviceBehaviors>
        <endpointBehaviors>
            <behavior name="RegistrationEndpointBehavior">
                <enableWebScript/>
            </behavior>
        </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
        <service name="Corp.EmployeeService" behaviorConfiguration="RegistrationBehavior">
            <endpoint address="" binding="webHttpBinding" contract="Corp.IEmployeeService" behaviorConfiguration="RegistrationEndpointBehavior" />
        </service>
    </services>
</system.serviceModel>
namespace Corp
{
    [ServiceContract]
    public interface IEmployeeService
    {
        [OperationContract]
        [WebInvoke(ResponseFormat = WebMessageFormat.Json, Method = "POST")]
        int Register(string username);
    }
}
在服务类本身上,我用以下属性修饰它:

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class EmployeeService : IEmployeeService
如前所述,我曾尝试使用jQuery或类似的方式访问服务:

$.ajax({
    cache: false,
    async: true,
    type: "POST",
    dataType: "json",
    url: "http://localhost/EmployeeService.svc/Register",
    data: '{"username":"test"}',
    contentType: "application/json;charset=utf-8",
    success: function (msg) {
        var status = msg.RegisterResult;
        if (status == 1) {
            alert('Success');
        } else {
            alert('Failure');
        }
    },
    error: function (msg) {
        alert('Exception - ' + msg);
    }
});
两者都返回404

由于我与一家共享托管公司托管此服务,我已在ServiceFactory上创建了我的服务,如下所示:

public class IisServiceHostFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        var newAddress = baseAddresses[0];

        if (!newAddress.AbsoluteUri.Contains("http://www."))
            newAddress = new Uri(newAddress.AbsoluteUri.Replace("http://", "http://www."));

        var webServiceHost = new IisServiceHost(serviceType, newAddress);
        return webServiceHost;
    }
}

public class IisServiceHost : ServiceHost
{
    public IisServiceHost(Type serviceType, params Uri[] baseAddresses): base(serviceType, baseAddresses) { }
}
试图从jQuery中点击帖子时出现帖子。404响应(来自简化为测试的不同示例服务)如下所示:

public class IisServiceHostFactory : ServiceHostFactory
{
    protected override ServiceHost CreateServiceHost(Type serviceType, Uri[] baseAddresses)
    {
        var newAddress = baseAddresses[0];

        if (!newAddress.AbsoluteUri.Contains("http://www."))
            newAddress = new Uri(newAddress.AbsoluteUri.Replace("http://", "http://www."));

        var webServiceHost = new IisServiceHost(serviceType, newAddress);
        return webServiceHost;
    }
}

public class IisServiceHost : ServiceHost
{
    public IisServiceHost(Type serviceType, params Uri[] baseAddresses): base(serviceType, baseAddresses) { }
}


此异常的文本是:HTTP 404。您正在查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请检查以下URL并确保其拼写正确

您将
Corp.EmployeeServiceService
作为合同-这不应该类似于
Corp.employeeservices.IService
?您可以尝试删除车身样式并让其采用默认值吗。另外,在您的RegistrationEndpointBehavior中,您的服务是否托管在IIS上?尝试使用Fiddler在服务上执行POST,看看会发生什么?它在IIS上。我已尝试创建自定义服务主机工厂。它正在做一个帖子。我将更新上面的帖子,以显示完整的404错误。最新的是,我可以点击.svc,但我不能点击方法。仍然得到404的。