简体   繁体   中英

WCF service not working on GoDaddy, How to I debug?

I have a C# Web Application built using Visual Studio Community. In the application I created a WCF (ajax-enabled) service which resides in [Services] folder called Service1.svc. The application works great locally.

I have successfully uploaded the application to a shared GoDaddy hosting account. However, the JavaScript calls to [Service1.svc] results in the following errors:

Above errors occur on the following line in JavaScript:

var myService = new Service1();

Why is it trying to reach "Service1.svc/js"? How do I go about debugging this issue?

Another question I have is what do I put for Namespace in [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;
        }
    }
}

Portion of 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>

Portion of 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>
....

Try to see why javascript proxy class wasn't created. or what issues it has.

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

that code should generate proxy class. Looks like it did not happen.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM