【问题标题】:WCF JSON Service not exposing methodsWCF JSON 服务不公开方法
【发布时间】:2012-06-14 16:56:03
【问题描述】:

我正在尝试创建一个返回 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);


}

【问题讨论】:

    标签: .net json wcf


    【解决方案1】:

    您如何定义您的服务文件?使用 .svc 文件还是使用路由?

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

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

    如有其他问题,请同时说明问题。

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 这不会改变任何东西。我仍然得到相同的结果。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多