2016-02-24 1 views
0

Я создал веб-службу, которая возвращает данные JSON. Он работает правильно при доступе через мой локальный хост.Ошибка веб-службы 404

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

, но когда я развернуть и попытаться работать на моем рабочем сервере я получаю следующее сообщение об ошибке:

Server Error in '/JSONWebService' Application. The resource cannot be found.

Описание: HTTP 404. Ресурс вы ищете (или один из его зависимостей) может быть удалено, если его имя изменилось или временно недоступно. Просмотрите следующий URL-адрес и убедитесь, что оно написано правильно.

Requested URL: /JSONWebService/Service1.svc/GetViewData

Если удалить/GetViewData из URL я получаю следующее сообщение:

Server Error in '/JSONWebService' Application. The resource cannot be found.

Описание: HTTP 404. Ресурс вы ищете (или один из его зависимостей) могло быть удалено, изменилось ли его имя или временно недоступно. Просмотрите следующий URL-адрес и убедитесь, что оно написано правильно.

Requested URL: /JSONWebService/Service1.svc/GetViewData

Если удалить/GetViewData из URL я получаю следующее сообщение:

Вы создали услугу.

Для проверки этой услуги вам необходимо создать клиента и использовать его для вызова службы. Вы можете сделать это с помощью инструмента 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; 
    } 
+0

вы используете правильный базовый адрес, вы можете попытаться подключиться к http://ac.gtest.oh.edu/JSONWebService/Service1.svc?GetViewData от клиента – Agalo

+0

, который не Работа. Я получаю то же сообщение «Вы создали услугу». – Bax

ответ

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>