【问题标题】:System.InvalidOperationException:The contract name 'XYZInterfce' could not be found in the list of contracts implemented by the service 'XYZWSImp'System.InvalidOperationException:在服务“XYZWSImp”实施的合同列表中找不到合同名称“XYZInterfce”
【发布时间】:2014-03-25 08:22:19
【问题描述】:

我正在尝试 Restful 服务。我收到此错误,我在做什么错?请帮忙 错误:

System.InvalidOperationException:合同名称“XYZ”不能 在服务“XYZWSImp”实施的合同列表中找到。 在 System.ServiceModel.Description.ConfigLoader.LookupContract(字符串 合同名称,字符串服务名称)在 System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase 主机,ServiceDescription 描述,ServiceElement serviceElement, Action`1 addBaseAddress, Boolean skipHost) at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader、ServiceDescription 描述、ServiceElement 服务部分)在 System.ServiceModel.ServiceHost.ApplyConfiguration() 在 System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses) 在 System.ServiceModel.ServiceHost..ctor(Type serviceType, Uri[] baseAddresses) 在 Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(类型类型, ServiceKind 种类)在 Microsoft.Tools.SvcHost.ServiceHostHelper.OpenService(ServiceInfo 信息)

我的界面类:

namespace XYZ
{
     [ServiceContract]
  interface XYZ_RestFullWSInterface
    {
         [OperationContract]
         [WebInvoke(
             Method = "GET",
             UriTemplate = "Encounter/{Identifier}",
             BodyStyle = WebMessageBodyStyle.WrappedRequest,
             ResponseFormat = WebMessageFormat.Json)]
         Encounter SearchEncounterByID(string Identifier);

App.Cofig

<pre><configuration>
...
 <system.web>
    <compilation debug="false" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="XYZ.XYZWSImp">
        <endpoint behaviorConfiguration="web" binding="webHttpBinding"
          contract="XYZ_RestFullWSInterface" />
      </service>
    </services>
    <behaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp helpEnabled="true" />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>
</pre>

【问题讨论】:

  • 你是如何使用这个接口到Service类的?有实现这个接口到Service类的吗?
  • 您是否尝试为端点的合同属性提供完全限定名称(包括名称空间)
  • 是的,我已经为服务类实现了这个接口并给出了限定名称。
  • 这是实现类:namespace XYZ { public class XYZWSImp:XYZ_RestFullWSInterface { public Encounter SearchEncounterByID(string Identifier) { EncounterByIDAdapter enounterByIdAdapter = new EncounterByIDAdapter(); return (Encounter) enounterByIdAdapter.read(Identifier); }

标签: c# html asp.net wcf restful-url


【解决方案1】:

试试这个。你没有在合约属性中传递完全限定名称

<services>
      <service name="XYZ.XYZWSImp">
        <endpoint behaviorConfiguration="web" binding="webHttpBinding"
          contract="XYZ.XYZ_RestFullWSInterface" />
      </service>
    </services>

【讨论】:

  • 我试过了,但现在给出了这个错误---> InvalidOperationException:找不到与绑定 WebHttpBinding 的端点的方案 http 匹配的基地址。注册的基地址方案是 []。
猜你喜欢
  • 2020-05-26
  • 1970-01-01
  • 1970-01-01
  • 2014-11-09
  • 2011-12-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-17
  • 2011-01-05
相关资源
最近更新 更多