【问题标题】:WCF service not working on GoDaddy, How to I debug?WCF 服务无法在 GoDaddy 上运行,我该如何调试?
【发布时间】:2015-12-22 11:52:25
【问题描述】:

我有一个使用 Visual Studio Community 构建的 C# Web 应用程序。在应用程序中,我创建了一个 WCF(启用 ajax)服务,该服务位于名为 Service1.svc 的 [Services] 文件夹中。该应用程序在本地运行良好。

我已成功将应用程序上传到共享的 GoDaddy 托管帐户。但是,对 [Service1.svc] 的 JavaScript 调用会导致以下错误:

JavaScript 中的以下行出现上述错误:

var myService = new Service1();

为什么要尝试访问“Service1.svc/js”? 我该如何调试这个问题?

我的另一个问题是我在 [ServiceContract(Namespace = "")] 中为命名空间添加了什么?

Service1.svc:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;
using System.Text;

namespace WebApplication1.Services
{
    [ServiceContract(Namespace = "")]
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service1
    {
        [OperationContract]
        public string DoWork(string m)
        {
            return m;
        }
    }
}

Site.Master 部分

....
<asp:ScriptManager runat="server">
     <Services>
          <asp:ServiceReference Path="~/Services/Service1.svc" />
     </Services>
....

Default.aspx

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server">

    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="CallMyWCF();" />

    <script>

        function CallMyWCF() {

            var myService = new Service1();
            myService.DoWork("hello world", onSuccess, null, null);
        }

        function onSuccess(result) {
            alert(result);
        }
    </script>

</asp:Content>

Web.Config 部分:

<configuration>
  ....

  <system.web>
    <customErrors mode="Off" />
    <trust level="Full" />

    <system.serviceModel>
        <behaviors>
          <endpointBehaviors>
            <behavior name="WebApplication1.Services.Service1AspNetAjaxBehavior">
              <enableWebScript />
            </behavior>
          </endpointBehaviors>
        </behaviors>
        <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
          multipleSiteBindingsEnabled="true" />
        <services>
          <service name="WebApplication1.Services.Service1">
            <endpoint address="" behaviorConfiguration="WebApplication1.Services.Service1AspNetAjaxBehavior"
              binding="webHttpBinding" contract="WebApplication1.Services.Service1" />
          </service>
        </services>
      </system.serviceModel>
....

【问题讨论】:

    标签: javascript c# asp.net wcf asp.net-ajax


    【解决方案1】:

    尝试查看为什么没有创建 javascript 代理类。或者它有什么问题。

    <asp:ScriptManager runat="server">
     <Services>
          <asp:ServiceReference Path="~/Services/Service1.svc" />
     </Services>
    

    该代码应该生成代理类。好像没有发生。

    【讨论】:

      猜你喜欢
      • 2018-03-14
      • 1970-01-01
      • 2014-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多