我正在尝试创建一个返回JSON对象的WCF服务。我的第一个问题是我没有看到服务方法暴露甚至调用它。当我这样调用服务方法时......“http:// localhost:60090 / VehicleDataService / detailbydivision?divisionId = 1& year = 2012”,我收到404错误。
... Web.Config中
<system.serviceModel>
<services>
<service name="GMEOG.VehicleDataService" behaviorConfiguration="metadataBehavior">
<endpoint address="" binding="webHttpBinding" contract="GMEOG.IVehicleDataService" behaviorConfiguration="VehicleDataServiceBehavior">
<identity>
<dns value="" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="metadataBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- 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="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="VehicleDataServiceBehavior">
<webHttp helpEnabled="true" defaultOutgoingResponseFormat="Json" />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
这是我的界面......
[ServiceContract(Namespace = "GMEOG.VehicleDataService", Name = "VehicleDataService")]
public interface IVehicleDataService
{
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json,
BodyStyle = WebMessageBodyStyle.WrappedResponse,
UriTemplate = "DetailByDivision?divisionId={divisionId}&year={year}")]
[return: MessageParameter(Name = "Vehicle")]
List<Vehicle> DetailByDivision(string divisionId, string year);
}
答案 0 :(得分:1)
您是如何定义服务文件的?使用.svc文件或使用路由?
如果是前者(假设svc文件名为“VehicleDataService.svc”),则地址应为http://localhost:60090/VehicleDataService
.svc /detailbydivision?divisionId=1&year=2012
。
如果是后者,请更新您的帖子如何使用路由服务。
如果还有别的,请说明问题。
答案 1 :(得分:0)
尝试在web.config中将主机添加到服务端点:
<host>
<baseAddresses>
<add baseAddress="http://localhost:60090/VehicleDataService" />
</baseAddresses>
</host>