【问题标题】:401 error on jsdebug file when changing WCF service to use an interface将 WCF 服务更改为使用接口时,jsdebug 文件出现 401 错误
【发布时间】:2011-07-22 09:06:44
【问题描述】:

情景。我将“启用 AJAX 的 WCF 服务”添加到我的 ASP.NET 应用程序(网络表单)。这会导致以下结果(长命名空间被截断):

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class MyService
{
    // To use HTTP GET, add [WebGet] attribute. (Default ResponseFormat is WebMessageFormat.Json)
    // To create an operation that returns XML,
    //     add [WebGet(ResponseFormat=WebMessageFormat.Xml)],
    //     and include the following line in the operation body:
    //         WebOperationContext.Current.OutgoingResponse.ContentType = "text/xml";
    [OperationContract]
    public void DoWork()
    {
        // Add your operation implementation here
        return;
    }

    // Add more operations here and mark them with [OperationContract]
}

我改变 [ServiceContract(命名空间 = "")] 到 [ServiceContract(Namespace = "http://domain.com/services")]

在我的页面上添加:

<asp:ScriptManagerProxy ID="ScriptManagerProxy1" runat="server">
    <Services>
        <asp:ServiceReference path="~/Services/MyService.svc" />
    </Services>
</asp:ScriptManagerProxy>

我还添加了一个 javascript 函数,以便我可以调用该服务:

函数调用DoWork(){ domain.com.services.MyService.DoWork(); }

该网站使用 Windows 身份验证运行。在我运行页面的时候,生成了jsdebug文件,找到了,domain.com.services.MyService.DoWork();工作没有问题。 FireBug 证实了这一点。所以我的下一步是创建一个接口并让服务类实现它。所以现在我有:

[ServiceContract(Namespace = "http://domain.com/services")]
public interface IMyService
{
    [OperationContract]
    void DoWork();
}

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)] 公共类 MyService : IMyService { 公共无效 DoWork() { // 在此处添加您的操作实现 返回; } }

并将 web.config 更改为 contract="Namespace.IMyService"

现在,我在 jsdebug 文件中收到 401 错误。有人见过这个吗?

感谢您的帮助。

【问题讨论】:

    标签: wcf windows-authentication webforms


    【解决方案1】:

    这是一条红鲱鱼。无论出于何种原因,服务上还有一个 mex 端点导致了这种情况的发生。我关闭了 mex 端点,401 消失了。并不是说这是一个解决方案,但至少我克服了我的错误。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-11
      • 1970-01-01
      • 2021-08-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-08
      相关资源
      最近更新 更多