【问题标题】:Web Service 404 ErrorWeb 服务 404 错误
【发布时间】:2016-02-24 17:29:32
【问题描述】:

我创建了一个返回 JSON 数据的 Web 服务。通过我的本地主机访问时它可以正常工作。

http://localhost:6553/Service1.svc/GetViewData

但是当我部署并尝试在我的生产服务器上运行时,我收到以下错误:

“/JSONWebService”应用程序中的服务器错误。 找不到资源。

描述:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请查看以下 URL 并确保其拼写正确。

请求的 URL:/JSONWebService/Service1.svc/GetViewData

如果我从 URL 中删除 /GetViewData,我会收到以下消息:

“/JSONWebService”应用程序中的服务器错误。 找不到资源。

描述:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请查看以下 URL 并确保其拼写正确。

请求的 URL:/JSONWebService/Service1.svc/GetViewData

如果我从 URL 中删除 /GetViewData,我会收到以下消息:

您已经创建了一个服务。

要测试此服务,您需要创建一个客户端并使用它来调用该服务。您可以使用命令行中的 svcutil.exe 工具执行此操作,语法如下:

svcutil.exe http://ac.gtest.oh.edu/JSONWebService/Service1.svc?wsdl

这是我的网络配置:

<?xml version="1.0"?>
<configuration>

<connectionStrings>
<add name="Web_TransferConnectionString" connectionString="Data Source=dart;Initial Catalog=Web_Transfer;Integrated Security=True"
  providerName="System.Data.SqlClient" />
</connectionStrings>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true"/>
</appSettings>
<system.web>
<compilation targetFramework="4.5"/>
<httpRuntime targetFramework="4.5"/>
<httpModules>
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"/>
</httpModules>
</system.web>
<system.serviceModel>
<services>
  <service name="JSONWebService.Service1">
    <endpoint address="../Service1.svc" binding="webHttpBinding" contract="JSONWebService.IService1" behaviorConfiguration="webBehaviour" />
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="false"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="false"/>
    </behavior>
  </serviceBehaviors>
  <endpointBehaviors>
    <behavior name="webBehaviour">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https"/>
</protocolMapping>
 <!-- <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true">
   <baseAddressPrefixFilters>
     <add prefix="http://www.JSONWebService.com/"/>
   </baseAddressPrefixFilters>
 </serviceHostingEnvironment> -->
</system.serviceModel>
<system.webServer>
<!--  <httpProtocol>
  <customHeaders>
    <add name="Access-Control-Allow-Origin" value="*" />
    <add name="Access-Control-Allow-Headers" value="Content-Type, Accept"/>
  </customHeaders>
 </httpProtocol> -->
 <modules runAllManagedModulesForAllRequests="true">
  <remove name="ApplicationInsightsWebTracking"/>
  <add name="ApplicationInsightsWebTracking" type="Microsoft.ApplicationInsights.Web.ApplicationInsightsHttpModule, Microsoft.AI.Web"
    preCondition="managedHandler"/>
 </modules>
   <!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
    -->
 <directoryBrowse enabled="true"/>
 <validation validateIntegratedModeConfiguration="false"/>

IService1.cs 文件:

 public interface IService1
{

    [OperationContract]
    [WebInvoke(Method = "GET", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "GetViewData")]
    //string GetData(string value);
    List<wsUpcomingDissertationsView> GetViewData();

    [OperationContract]
    CompositeType GetDataUsingDataContract(CompositeType composite);

    // TODO: Add your service operations here
}

Service1.svc.cs

 public class Service1 : IService1
{
    //public string GetData(string value)
    //{
    //    return string.Format("You entered: {0}", value);
    //}

    public List<wsUpcomingDissertationsView> GetViewData()
    {

        Upcoming_Dissertations_ViewDataContext dc = new Upcoming_Dissertations_ViewDataContext();
        List<wsUpcomingDissertationsView> results = new List<wsUpcomingDissertationsView>();

        foreach (Upcoming_Dissertations_View UDV in dc.Upcoming_Dissertations_Views)
        {
            results.Add(new wsUpcomingDissertationsView()
            {
                First_Name = UDV.FIRST_NAME,
                Last_Name = UDV.LAST_NAME,
                exam_oral_date = UDV.exam_oral_date,
                Expr1 = UDV.Expr1,

            });
        }

        return results;
    }

【问题讨论】:

标签: c# asp.net web-services wcf


【解决方案1】:

更新: 经过数小时的反复试验,我让它工作了。我做了一些修改:

<system.serviceModel>
<services>
  <service name="JSONWebService.Service1">
    <endpoint address="" binding="webHttpBinding" contract="JSONWebService.IService1" bindingConfiguration="webBinding" behaviorConfiguration="webBehaviour"/>
  </service>
</services>
<bindings>
  <webHttpBinding>
    <binding name="webBinding">
      <security mode="Transport">
      </security>
    </binding>
  </webHttpBinding>
</bindings>

【讨论】:

    猜你喜欢
    • 2017-02-07
    • 2018-02-04
    • 1970-01-01
    • 2023-03-30
    • 2015-12-29
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多