2012-06-14 116 views
0

我想创建一个返回JSON对象的WCF服务。我的第一个问题是我没有看到暴露甚至调用它的服务方法。当我调用这样的服务方法...“http:// localhost:60090/VehicleDataService/detailbydivision?divisionId = 1 & year = 2012”,我得到一个404错误。WCF JSON服务不公开方法

的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

尝试在web.config中添加主机到您的服务端点:

<host> 
    <baseAddresses> 
    <add baseAddress="http://localhost:60090/VehicleDataService" /> 
    </baseAddresses> 
</host> 
+0

这不会改变任何东西。我仍然得到相同的结果。 – Adam

1

你如何定义你的服务文件?使用.svc文件或使用路由?

如果是前者(假设称为 “VehicleDataService.svc” 一个SVC文件),地址应为http://localhost:60090/VehicleDataService.SVC/detailbydivision?divisionId=1&year=2012

如果是后者,请更新您的文章如何使用路由服务。

如果还有其他问题,请在问题上说明。