Web服务404错误

时间:2016-02-24 17:29:32

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

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

  

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

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

  

' / JSONWebService'中的服务器错误应用。   无法找到资源。

描述:HTTP 404.您正在查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,确保拼写正确。

  

请求的网址:/JSONWebService/Service1.svc/GetViewData

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

  

' / JSONWebService'中的服务器错误应用。   无法找到资源。

描述:HTTP 404.您正在查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,确保拼写正确。

  

请求的网址:/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;
    }

1 个答案:

答案 0 :(得分:0)

更新: 我经过几个小时的试验和错误后才开始工作。我做了一些修改:

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