2012-06-14 40 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

如果是後者,請更新您的文章如何使用路由服務。

如果還有其他問題,請在問題上說明。