namespace Ajax_Enabled_Wcf_Service
{
[ServiceContract(Namespace = "Ajax_Enabled_Wcf_Service")]
public class Service1
{
[OperationContract]
public double CostOfSandwiches(int quantity)
{
return 1.25 * quantity;
}
// Add more operations here and mark them with [OperationContract]
}
}
and here is my default web.config file
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="Ajax_Enabled_Wcf_Service.Service1AspNetAjaxBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<services>
<service name="Ajax_Enabled_Wcf_Service.Service1">
<endpoint address="" behaviorConfiguration="Ajax_Enabled_Wcf_Service.Service1AspNetAjaxBehavior"
binding="webHttpBinding" contract="Ajax_Enabled_Wcf_Service.Service1" />
<!--<endpoint address="mex" binding ="mexHttpBinding" contract="IMetadataExchange"/>-->
</service>
</services>
</system.serviceModel>
我尝试通过键入其URL
来将服务称为RESTFUL http://localhost:50255/Service1.svc
因为我的绑定是webHttpBinding。这给了我一个错误,说明在服务Service1实现的合同列表中找不到合同名称IMetadataExchange。将ServiceMetadataBehavior直接添加到配置文件或ServiceHost以启用对此合同的支持。当我评论
时 <endpoint address="mex" binding ="mexHttpBinding" contract="IMetadataExchange"/>
并尝试将我的Service1.svc文件从VS运行到它所说的浏览器中 目前已禁用此服务的元数据发布。
然后我将webHttBinding更改为basicHttpBinding以获取SOAP服务并尝试通过WCF测试客户端添加它,它说无法添加服务。可能无法访问服务元数据。确保您的服务正在运行并公开元数据。
我已经浏览过如此多的在线文章和谷歌搜索堆栈流本身,但没有什么对我有用。