IIS部署Wcf服务出错

jiao006 2013-08-08 04:09:41
最近在学习ios访问sql数据库,看到网上有关于ios通过wcf service访问sql的例子,就跟着操作了一遍,结果到配置iis的时候就出问题了。
使用vs访问数据库完全正常

发布到iis之后就只能访问到这个路径

到底是哪里出问题了,大神帮帮忙
...全文
176 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
把我的配置文件贴出来供参考。
<system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="SecureCloudWebService.SecureCloudAspNetAjaxBehavior">
          <enableWebScript />
        </behavior>
      </endpointBehaviors>
      <serviceBehaviors>
        <behavior name="EnableMetadataBehaviors">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <!--bindings>
      <webHttpBinding>
        <binding name="test" crossDomainScriptAccessEnabled="true"></binding>  
      </webHttpBinding>
    </bindings-->
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
    <services>
      <service name="SecureCloudWebService.SecureCloud" behaviorConfiguration="EnableMetadataBehaviors">
        <endpoint address="" behaviorConfiguration="SecureCloudWebService.SecureCloudAspNetAjaxBehavior" binding="webHttpBinding" contract="SecureCloudWebService.SecureCloud" />
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
  </system.serviceModel>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v11.0" />
      </parameters>
    </defaultConnectionFactory>
  </entityFramework>
  <connectionStrings>
    <!--add name="UserDeviceDbContext"
       connectionString="Data Source=localhost;Initial Catalog=test;User Id=sa;Password=123456"
       providerName="System.Data.SqlClient"/-->
    <add name="DW_iSecureCloudEntities" connectionString="metadata=res://*/Models.DW_iSecureCloud.csdl|res://*/Models.DW_iSecureCloud.ssdl|res://*/Models.DW_iSecureCloud.msl;provider=System.Data.SqlClient;provider connection string="data source=192.168.1.128;initial catalog=DW_iSecureCloud;user id=sa;password=861004;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
  </connectionStrings>
jiao006 2013-08-09
  • 打赏
  • 举报
回复
引用 1 楼 hard_learner 的回复:
可以访问到这个路径是正确的呀,你在程序中创建一个WCF服务的客户端然后调用方法应该就可以返回你需要的数据了
目录是能访问,但是要激活我想要的方法读取数据,必须要在这个路径下加上“/json/employees”这个结点。 接口中的代码是这样的

[WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "json/employees")]
jiao006 2013-08-08
  • 打赏
  • 举报
回复
怎么人这么少啊,是我发的位置不对么
jiao006 2013-08-08
  • 打赏
  • 举报
回复
GetEmployee.svc.cs

namespace WcfService
{
    // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码、svc 和配置文件中的类名“GetEmployee”。
    // 注意: 为了启动 WCF 测试客户端以测试此服务,请在解决方案资源管理器中选择 GetEmployee.svc 或 GetEmployee.svc.cs,然后开始调试。
    public class GetEmployee : IGetEmployee
    {
        public List<Employee> GetAllEmployeesMethod()
        {
            List<Employee> mylist = new List<Employee>();

            using (SqlConnection conn = new SqlConnection("server=(172.168.40.99);database=Emp;userid=sa;password=zaq1@WSX"))
            {
                conn.Open();

                string cmdStr = String.Format("Select firstname,lastname,salary from EmpInfo");
                SqlCommand cmd = new SqlCommand(cmdStr, conn);
                SqlDataReader rd = cmd.ExecuteReader();
                if (rd.HasRows)
                {
                    while (rd.Read())
                        mylist.Add(new Employee(rd.GetString(0), rd.GetString(1), rd.GetDecimal(2)));
                }
                conn.Close();
            }

            return mylist;
        }
    }

    [DataContract]
    public class Employee
    {
        [DataMember]
        public string firstname { get; set; }
        [DataMember]
        public string lastname { get; set; }
        [DataMember]
        public decimal salary { get; set; }
        public Employee(string first, string last, decimal sal)
        {
            firstname = first;
            lastname = last;
            salary = sal;
        }
    }
}
IGetEmployee.cs

namespace WcfService
{
    // 注意: 使用“重构”菜单上的“重命名”命令,可以同时更改代码和配置文件中的接口名“IGetEmployee”。
    [ServiceContract]
    public interface IGetEmployee
    {
        [OperationContract]
        [WebInvoke(Method = "GET",
            ResponseFormat = WebMessageFormat.Json,
            BodyStyle = WebMessageBodyStyle.Wrapped,
            UriTemplate = "json/employees")]
        //method
        List<Employee> GetAllEmployeesMethod();
    }
}
web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <services>
      <service name="WcfService.GetEmployee" behaviorConfiguration="EmpServiceBehaviour">
        <endpoint address="" binding="webHttpBinding" contract="WcfService.IGetEmployee" behaviorConfiguration="web">
        </endpoint>
        <host>
          <baseAddresses>
            <add baseAddress="http://localhost:8000/" />
          </baseAddresses>
        </host>
      </service>
    </services>
    
    <behaviors>
      <serviceBehaviors>
        <behavior name="EmpServiceBehaviour">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp helpEnabled="true" automaticFormatSelectionEnabled="true" />
        </behavior>
      </endpointBehaviors>
    </behaviors>
  </system.serviceModel>
    <system.webServer>
        <directoryBrowse enabled="true" />
    </system.webServer>
</configuration> 
jiao006 2013-08-08
  • 打赏
  • 举报
回复
引用 2 楼 xuhang01 的回复:
http://www.cnblogs.com/gracexu/archive/2013/04/23/3037203.html 访问的数据库是不是文件类型的? 看看是否有文件路径不正确
访问的是sql数据库。我不确定配置文件是不是配置正确。我在下面贴出文件的源代码供大家参考。
  • 打赏
  • 举报
回复
http://www.cnblogs.com/gracexu/archive/2013/04/23/3037203.html 访问的数据库是不是文件类型的? 看看是否有文件路径不正确
hard_learner 2013-08-08
  • 打赏
  • 举报
回复
可以访问到这个路径是正确的呀,你在程序中创建一个WCF服务的客户端然后调用方法应该就可以返回你需要的数据了

8,327

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 IIS
社区管理员
  • IIS
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧