Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF:未能添加服务。服务元数据可能无法访问_C#_Asp.net_Web Services_Wcf_Service - Fatal编程技术网

C# WCF:未能添加服务。服务元数据可能无法访问

C# WCF:未能添加服务。服务元数据可能无法访问,c#,asp.net,web-services,wcf,service,C#,Asp.net,Web Services,Wcf,Service,我搜索了这个问题,得到了太多的链接,并尝试了其中的大部分,但我的问题没有解决。我正在管理模式下运行我的VS。 我创建了一个新项目,然后将WCF服务添加到我的项目中。我想通过ajax调用我的服务 这是我在Sevice.cs和Iservice.cs中的代码 namespace WcfWithAjax { [ServiceContract] public interface IService { [OperationContract] [WebI

我搜索了这个问题,得到了太多的链接,并尝试了其中的大部分,但我的问题没有解决。我正在管理模式下运行我的VS。 我创建了一个新项目,然后将WCF服务添加到我的项目中。我想通过ajax调用我的服务

这是我在Sevice.cs和Iservice.cs中的代码

namespace WcfWithAjax
{
    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json)]
        string GetEmployeeList();
    }
}

名称空间WcfWithAjax
{
[AspNetCompatibilityRequirements(RequirementsMode=AspNetCompatibilityRequirementsMode.Allowed)]
公共课服务:IService
{
[经营合同]
公共字符串GetEmployeeList()
{
string str=ConfigurationManager.ConnectionStrings[“connect”].ConnectionString;
IList employeeList=新列表();
使用(SqlConnection con=newsqlconnection(str))
{
con.Open();
SqlCommand cmd=新的SqlCommand(“从员工中选择*”,con);
SqlDataReader dr=cmd.ExecuteReader();
while(dr.Read())
{
employeeList.Add(新员工()
{
Id=dr.GetInt32(0),
Name=dr.GetString(1),
位置=dr.GetString(2),
年龄=博士GetInt32(3),
薪水=博士GetInt32(4)
});
}
con.Close();
}
JavaScriptSerializer objJson=新的JavaScriptSerializer();
返回objJson.Serialize(employeeList);
}
}
}
然后配置了我的web.config文件 如下

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metadataBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>

    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
      multipleSiteBindingsEnabled="true" />
    <services>
      <service name="WcfWithAjax.Service" behaviorConfiguration="metadataBehavior">
        <endpoint address=""  binding="webHttpBinding" contract="WcfWithAjax.IService" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
  </system.serviceModel>

现在我正在调试我的项目,但它正在显示

添加服务失败。服务元数据可能无法访问。确保您的服务正在运行并公开元数据

这里是一些链接,我得到了,但无法解决我的问题


更改您的配置代码

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metadataBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="ServiceAspNetAjaxBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
      <service name="WcfWithAjax.Service" behaviorConfiguration="metadataBehavior">
        <endpoint address=""  binding="webHttpBinding" contract="WcfWithAjax.IService" behaviorConfiguration="ServiceAspNetAjaxBehavior"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
  </system.serviceModel>


任何帮助。如果不需要,请回复删除
mex
绑定。
<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="metadataBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="ServiceAspNetAjaxBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
    <services>
      <service name="WcfWithAjax.Service" behaviorConfiguration="metadataBehavior">
        <endpoint address=""  binding="webHttpBinding" contract="WcfWithAjax.IService" behaviorConfiguration="ServiceAspNetAjaxBehavior"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
  </system.serviceModel>