C# Web服务404错误
我创建了一个返回JSON数据的web服务。通过我的本地主机访问时,它工作正常 但是,当我部署并尝试在生产服务器上运行时,会出现以下错误: “/JSONWebService”应用程序中出现服务器错误。 找不到资源 描述:HTTP404。您正在查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请检查以下URL并确保其拼写正确 请求的URL:/JSONWebService/Service1.svc/GetViewData 如果从URL中删除/GetViewData,则会收到以下消息: “/JSONWebService”应用程序中出现服务器错误。 找不到资源 描述:HTTP404。您正在查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请检查以下URL并确保其拼写正确 请求的URL:/JSONWebService/Service1.svc/GetViewData 如果从URL中删除/GetViewData,则会收到以下消息: 您已经创建了一个服务 要测试此服务,您需要创建一个客户机并使用它调用该服务。可以使用命令行中的svcutil.exe工具,使用以下语法执行此操作: svcutil.exe 这是我的网页配置:C# Web服务404错误,c#,asp.net,web-services,wcf,C#,Asp.net,Web Services,Wcf,我创建了一个返回JSON数据的web服务。通过我的本地主机访问时,它工作正常 但是,当我部署并尝试在生产服务器上运行时,会出现以下错误: “/JSONWebService”应用程序中出现服务器错误。 找不到资源 描述:HTTP404。您正在查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请检查以下URL并确保其拼写正确 请求的URL:/JSONWebService/Service1.svc/GetViewData 如果从URL中删除/GetViewData,则会收到以下消息:
<?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
}
公共接口IService1
{
[经营合同]
[WebInvoke(Method=“GET”,ResponseFormat=WebMessageFormat.Json,BodyStyle=WebMessageBodyStyle.Wrapped,UriTemplate=“GetViewData”)]
//字符串GetData(字符串值);
列出GetViewData();
[经营合同]
CompositeType GetDataUsingDataContract(CompositeType composite);
//TODO:在此处添加服务操作
}
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:IService1
{
//公共字符串GetData(字符串值)
//{
//返回string.Format(“您输入:{0}”,value);
//}
公共列表GetViewData()
{
即将发表的论文\u ViewDataContext dc=新的即将发表的论文\u ViewDataContext();
列表结果=新列表();
foreach(即将发表的论文查看dc中的UDV。即将发表的论文查看)
{
结果.添加(新WSupComingDeservationsView()
{
First_Name=UDV.First_Name,
Last_Name=UDV.Last_Name,
考试口试日期=UDV.考试口试日期,
Expr1=UDV.Expr1,
});
}
返回结果;
}
更新:
经过几个小时的反复试验,我终于让它工作了。我做了一些修改:
<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>
如果您使用的是正确的基址,是否可以尝试从客户端连接到不起作用的。我收到了相同的消息“您已经创建了一个服务”。。