托管到服务器时WCF出错

时间:2012-10-09 12:34:56

标签: c# wcf iis web-config

我创建了一个wcf服务,此服务在服务器上部署后发出错误 本服务在本地主机上工作正常,所以我不知道我错在哪里

enter image description here

我的 Service.svc 是:

<%@ ServiceHost Language="C#" Debug="true" Service="mobile.Service" CodeBehind="Service.svc.cs" %>

我的 web.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <!--Path for Photo Gallery Images-->
    <add key="PhotoGalleryPath" value="http://www.abc.com/photogallery/"/>
    <!--Path for Video Gallery Images-->
    <add key="VideoPath" value="http://www.abc.com/video/"/>
    <!--Path for Video URL-->
    <add key="VideoURLPath" value="http://ventunotech.com/watch/"/>
    <!--Path for Web URL for Share News through mail, FB, Twitter-->
    <add key="WebUrlforNews" value="http://www.abc.com/news.aspx?id="/>
    <add key="WebUrlforArticle" value="http://www.abc.com/article.aspx?id="/>
    <!--Folder Name with Path for News and Article Images (Change this according to Your Server Folder Path) and give this folder to write permission-->
    <add key="ImagePath" value="http://www.abc.com/mobile/images/"/>
  </appSettings>
  <connectionStrings>
    <add name="con" connectionString="Data Source=184.122.1.55;Initial Catalog=Data;Integrated Security=SSPI;"/>
  </connectionStrings>
  <system.web>
    <compilation debug="true"/>
  </system.web>
  <system.serviceModel>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
    <services>
      <service behaviorConfiguration="APIService.ServiceBehavior" name="APIService.Service">
        <endpoint address="" behaviorConfiguration="web" binding="webHttpBinding" contract="APIService.IService"/>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="APIService.ServiceBehavior">
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <bindings>
      <webHttpBinding>
        <binding name="web" maxBufferPoolSize="1500000" maxReceivedMessageSize="1500000" maxBufferSize="1500000">
          <readerQuotas maxArrayLength="656000" maxBytesPerRead="656000" maxDepth="32" maxNameTableCharCount="656000" maxStringContentLength="656000"/>
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>

我的 IService.cs

namespace APIService
{
    [ServiceContract]
    public interface IService
    {
        [OperationContract]
        [WebInvoke(Method = "GET", UriTemplate = "/GetCities", BodyStyle = WebMessageBodyStyle.WrappedRequest,
                    RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        ItemList GetCities();

        [OperationContract]
        [WebInvoke(Method = "GET", UriTemplate = "/GetStates", BodyStyle = WebMessageBodyStyle.WrappedRequest,
                    RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        ItemList GetStates();  

 }
    [DataContract]
    public class Item
    {
        [DataMember]
        public string ID { get; set; }
        [DataMember]
        public string Name { get; set; }
    }
    [DataContract]
    public class ItemList
    {
        [DataMember]
        public List<Item> Items { get; set; }
    }

}

我的 Service.svc.cs

namespace APIService
{
    [AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
    public class Service : IService
    {
        SqlConnection offcon = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
        SqlDataAdapter adp;
        SqlCommand cmd;
        DataSet ds = new DataSet();
        DataSet ds1 = new DataSet();
        ItemList items = new ItemList();
        NewsList newslist = new NewsList();
        CommentList commentslist = new CommentList();
        UserProfile userPrf = new UserProfile();

        #region CityList
        public ItemList GetCities()
        {
            try
            {
                adp = new SqlDataAdapter("Select * from tblCity", offcon);
                adp.Fill(ds, "City");

                DataTable City = ds.Tables["City"];
                var item = (from d in City.AsEnumerable()
                            select new Item
                            {
                                ID = d.Field<Int32>("intCityId").ToString(),
                                Name = d.Field<string>("strTitle")
                            }).ToList();

                items.Items = item;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return new ItemList { Items = items.Items };
        }
        #endregion

        #region StateList
        public ItemList GetStates()
        {
            try
            {
                adp = new SqlDataAdapter("select * from tblState ", offcon);
                adp.Fill(ds, "State");

                DataTable State = ds.Tables["State"];
                var item = (from d in State.AsEnumerable()
                            select new Item
                            {
                                ID = d.Field<Int32>("intStateId").ToString(),
                                Name = d.Field<string>("strTitle")
                            }).ToList();
                items.Items = item;
            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            return new ItemList { Items = items.Items };
        }
        #endregion
}
}

我不知道我错在哪里,我已经尝试了以下链接的答案,但对我没有任何作用:

如果有人可以提供帮助......

1 个答案:

答案 0 :(得分:1)

错误表示IIS无法找到类型mobile.Service。可能有很多原因导致它无法找到类型。我建议你也在服务属性中指定程序集名称。

此外,您可以使用ILDasm检查程序集是否确实包含该类型。

<强>更新

尝试

<%@ ServiceHost Language="C#" Debug="true" Service="APIService.Service" CodeBehind="Service.svc.cs" %>