WCF服务在本地工作,在远程服务器上返回404未找到

时间:2015-11-06 21:26:40

标签: c# wcf server http-status-code-404

您好,我正在寻找很多类似的问题而且我没有找到答案,请帮助我。我的wcf服务在我的本地机器上工作正常,在远程服务上它给我404.这是我的web配置。

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>

  <configSections>
    <sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
      <section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
      <section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
    </sectionGroup>
  </configSections>

  <appSettings>
    <add key="GoogleAnalytics:PropertyID" value="" />
    <add key="webpages:Version" value="3.0" />
    <add key="webpages:Enabled" value="true" />
    <add key="vs:EnableBrowserLink" value="false" />
  </appSettings>

    <system.web>
      <compilation debug="true" targetFramework="4.5.1" />
      <httpRuntime targetFramework="4.5.1" />
      <customErrors mode="Off"/>
      <securityPolicy>
        <trustLevel name="Full" policyFile="internal"/>
      </securityPolicy> 
    </system.web>

  <system.web.webPages.razor>
    <host factoryType="System.Web.WebPages.Razor.WebRazorHostFactory, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
    <pages pageBaseType="System.Web.WebPages.WebPage">
      <namespaces>
        <add namespace="System.Web.Configuration" />
        <add namespace="System.Web.Optimization" />
        <add namespace="System.Web.Routing" />
      </namespaces>
    </pages>
  </system.web.webPages.razor>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.OAuth" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security.Cookies" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.2.0" newVersion="2.0.2.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Antlr3.Runtime" publicKeyToken="eb42632606e9261f" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.5.0.2" newVersion="3.5.0.2" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>


  <location path="crossdomain.xml">
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false"/>
      <modules runAllManagedModulesForAllRequests="true" /> 
    </system.webServer>
  </location> 
    <system.serviceModel>
    <bindings>
      <webHttpBinding>
        <binding maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647" maxBufferSize="2147483647" transferMode="Streamed"></binding>
      </webHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="ServiceBehaviour" name="App.RozankaWeb.Service.EmailService">
        <endpoint address="http:/mydomain.com/Service/EmailService.svc" behaviorConfiguration="web" binding="webHttpBinding" contract="App.RozankaWeb.Service.IEmailService" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
      <serviceActivations>
        <add relativeAddress="Service/EmailService.svc" service="App.RozankaWeb.Service.EmailService"/>
      </serviceActivations>
    </serviceHostingEnvironment>
  </system.serviceModel>
</configuration>

这是我的角度控制器,它调用服务(Works local:))

$scope.sendEmail = function (Name, emailFrom, phoneNumber, bodyOrigin) {

        var emailTo = 'mymail@gmail.com';
        var emailToName = "my name";
        var subject = 'My subject';
        var isBodyHtml = false;
        var body = bodyOrigin + " " + "Kontakt telefona: " + phoneNumber;

        $http.post("/Service/EmailService.svc/SendEmail", {

            emailFrom: emailFrom,
            emailFromName: Name,
            emailTo: emailTo,
            emailToName: emailToName,
            subject : subject,
            body : body,
            isBodyHtml: isBodyHtml,

        }, { timeout: 60000 })
        .success(function (response) {
            $scope.array = "Email sent";
        })
        .error(function (data, status, headers, config) {

        });

这是我的服务

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Runtime.Serialization;
using System.Security.Cryptography.X509Certificates;
using System.ServiceModel;
using System.Text;

namespace App.RozankaWeb.Service
{
  public class EmailService : IEmailService
  {

    public void SendEmail(PostEmail postEmail)
    {

      MailAddress from = new MailAddress(postEmail.emailFrom, postEmail.emailFromName);
      MailAddress to = new MailAddress(postEmail.emailTo, postEmail.emailToName);
      MailMessage message = new MailMessage(from, to);
      message.Subject = postEmail.subject;
      message.Body = postEmail.body;

      SmtpClient client = new SmtpClient
      {
        Host = "smtp.mydomain.com",
        Port = 587,
        UseDefaultCredentials = false,
        Credentials = new NetworkCredential("mycredential@.com", "mypassword"),
        DeliveryMethod = SmtpDeliveryMethod.Network,
        EnableSsl = true,
        Timeout = 10000
      };

      Console.WriteLine("Sending an e-mail message to {0} and {1}.", to.DisplayName, message.Bcc.ToString());
      try
      {

        ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
        {
          return true;
        };
        client.Send(message);
      }
      catch (Exception ex)
      {
        Console.WriteLine("Exception caught in CreateBccTestMessage(): {0}",
                    ex.ToString());
      }

    }

  }

  public class PostEmail
  {

    public string emailTo;
    public string emailToName;
    public string subject;
    public string body;
    public string emailFrom;
    public string emailFromName;
    public bool isBodyHtml;

  }

}

和我的界面

{
  [ServiceContract]
  public interface IEmailService
  {
    [OperationContract]
    [WebInvoke(Method = "POST", UriTemplate = "SendEmail", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Bare)]
    void SendEmail(PostEmail postEmail);

  }
}

我知道这是很多代码,但请看看并给我一个帮助,我感谢任何帮助:)

0 个答案:

没有答案