从WCF服务中删除.svc会导致找不到端点

时间:2012-04-01 17:20:17

标签: c# winforms wcf

所以今天我决定从WCF服务中删除.svc文件,并开始在线查看。

以下是我所做的一步一步的过程:

第1步:我添加了global.asax

void Application_Start(object sender, EventArgs e) 
{
    RouteTable.Routes.Add(new ServiceRoute("Authorization", new WebServiceHostFactory(), typeof(Authenticator)));
    RouteTable.Routes.Add(new ServiceRoute("Miscellaneous", new WebServiceHostFactory(), typeof(Misc)));
}

注意:Authenticator和Misc是我的界面实现

第2步:我启用了asp.net兼容性

<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />

第3步:我在每个界面实施中添加了[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]

第4步:我必须将[WebInvoke(BodyStyle = WebMessageBodyStyle.WrappedRequest)]添加到界面中的每个方法。我不知道这是做什么的,但没有它就错了。

现在它“正常”但是当我导航到root / Authorization(授权是我的第一个服务的名称)时,它告诉我没有找到端点。

我的端点在我的web.config中指定为:

        <service name="AuthenticatorService.Authenticator">
            <endpoint address="auth" binding="basicHttpBinding" name="AuthEndpoint"
              contract="AuthInterface.IAuthenticator" />
            <endpoint address="mex" binding="mexHttpBinding" name="MetadataEndpoint"
              contract="IMetadataExchange" />
        </service>

我对WCF很新,所以这可能是一个愚蠢的错误。

1 个答案:

答案 0 :(得分:3)

你在这里混合了两种技术 - 在你的配置中,你定义了basicHttpBinding这是一个SOAP服务 - 然而,在你的服务路由中,你传入一个用于REST的WebServiceHost WCF中的服务(基于webHttpBinding)。

试试这个 - 只需在ServiceHostFactory文件中使用“常规”(面向SOAP)global.asax

void Application_Start(object sender, EventArgs e) 
{
    RouteTable.Routes.Add(
       new ServiceRoute("Authorization", 
                        new ServiceHostFactory(), typeof(Authenticator)));
    RouteTable.Routes.Add(
       new ServiceRoute("Miscellaneous", 
                        new ServiceHostFactory(), typeof(Misc)));
}