我正在尝试Restful服务。我收到这个错误,我做错了什么?请帮忙 错误:
System.InvalidOperationException:合同名称' XYZ'不可能 在服务' XYZWSImp'中实施的合同列表中找到。 在System.ServiceModel.Description.ConfigLoader.LookupContract(String contractName,String serviceName)at System.ServiceModel.Description.ConfigLoader.LoadServiceDescription(ServiceHostBase host,ServiceDescription描述,ServiceElement serviceElement, Action`1 addBaseAddress,Boolean skipHost)at System.ServiceModel.ServiceHostBase.LoadConfigurationSectionInternal(ConfigLoader configLoader,ServiceDescription描述,ServiceElement serviceSection)at System.ServiceModel.ServiceHost.ApplyConfiguration()at System.ServiceModel.ServiceHostBase.InitializeDescription(UriSchemeKeyedCollection baseAddresses)在System.ServiceModel.ServiceHost..ctor(Type serviceType,Uri [] baseAddresses)at Microsoft.Tools.SvcHost.ServiceHostHelper.CreateServiceHost(Type type, 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>
答案 0 :(得分:1)
试试这个。你没有在合同属性
中传递完全限定名<services>
<service name="XYZ.XYZWSImp">
<endpoint behaviorConfiguration="web" binding="webHttpBinding"
contract="XYZ.XYZ_RestFullWSInterface" />
</service>
</services>