添加WebService ASP.net时出错

时间:2015-11-25 15:29:09

标签: asp.net

当我运行WCF时,它会抛出以下错误:

  

错误:无法从localhost获取元数据:3682 / Service1.svc如果这是您有权访问的Windows(R)Communication Foundation服务,请检查您是否已在指定地址启用元数据发布。有关启用元数据发布的帮助,请参阅go.microsoft.com/fwlink/?LinkId=65455上的MSDN文档.WS-Metadata Exchange错误URI:localhost:3682 / Service1.svc元数据包含无法解析的引用:'本地主机:3682 / Service1.svc”。没有端点侦听localhost:3682 / Service1.svc可以接受该消息。这通常是由错误的地址或SOAP操作引起的。有关更多详细信息,请参阅InnerException(如果存在)。无法连接到远程服务器无法建立连接,因为目标计算机主动拒绝它127.0.0.1:3682HTTP GET错误URI:localhost:3682 / Service1.svc下载'localhost:3682 / Service1.svc'时出错。无法连接到远程服务器无法建立连接,因为目标计算机主动拒绝它127.0.0.1:3682 **

这是我的 Web.config

<?xml version="1.0"?>
<configuration>
    <connectionStrings>
        <add name="Shop_DTBEntities" connectionString="metadata=res://*/shop_DTB.csdl|res://*/shop_DTB.ssdl|res://*/shop_DTB.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=Shop_DTB;persist security info=True;user id=sa;password=1234567;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    </connectionStrings>

    <appSettings>
        <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
    </appSettings>
    <system.web>
        <compilation debug="true" targetFramework="4.5" />
        <httpRuntime targetFramework="4.5" maxRequestLength ="262144" executionTimeout="103600"/>
    </system.web>

    <system.serviceModel>


        <services>
            <!-- Note: the service name must match the configuration name for the service implementation. -->
            <service name="WcfService1.Service1" behaviorConfiguration="MyServiceTypeBehaviors" >
                <!-- Add the following endpoint.  -->
                <!-- Note: your service must have an http base address to add this endpoint. -->
                <endpoint contract="WcfService1.IService1" binding="mexHttpBinding" address="mex" />
            </service>
        </services>

        <behaviors>
            <serviceBehaviors>
                <behavior name="MyServiceTypeBehaviors" >
                    <!-- Add the following element to your service behavior configuration. -->
                    <serviceMetadata httpGetEnabled="true" />
                </behavior>
            </serviceBehaviors>
        </behaviors>

        <!--<protocolMapping>
      <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>

    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />-->
    </system.serviceModel>

    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true"/>
        <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
        <directoryBrowse enabled="true"/>
    </system.webServer>

</configuration>

IService:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using Entities;
namespace WcfService1
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the interface name "IService1" in both code and config file together.
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        IEnumerable<Product_Categories> GetAllCategory();
        [OperationContract]
        IEnumerable<Product> GetProductBestSeller(int idCategory);

        [OperationContract]
        IEnumerable<Product> GetProByProtype_ID(int idProducttype);

        [OperationContract]
        IEnumerable<Product> GetProByCate_ID(int idCate);

        [OperationContract]
        IEnumerable<Product_Type> GetAllProductType();
    }
}

Webservice1

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using BAL;
using Entities;
namespace WcfService1
{

    public class Service1 : IService1
    {
        public IEnumerable<Product_Categories> GetAllCategory()
        {
            return new CategoryBAL().GetAllCategoryBAL();
        }

        public IEnumerable<Product> GetProductBestSeller(int idCategory)
        {
            return new ProductBAL().GetProductBestSeller_BAL(idCategory);
        }

        public IEnumerable<Product> GetProByProtype_ID(int idProducttype)
        {
            return new ProductBAL().GetProByProtype_ID_BAL(idProducttype);
        }

        public IEnumerable<Product> GetProByCate_ID(int idCate)
        {
            return new ProductBAL().GetProByCate_ID_BAL(idCate);
        }

        public IEnumerable<Product_Type> GetAllProductType()
        {
            return new TypeBAL().GetAllProductType();
        }
    }
}

0 个答案:

没有答案