简体   繁体   English

托管到服务器时WCF中的错误

[英]Error in WCF while hosting to the server

I have created a wcf Service this service is giving an error after deploy on the server this Service is working fine at Local host so i don't know where i am wrong 我创建了一个wcf服务,该服务在服务器上部署后出现错误,该服务在本地主机上运行良好,所以我不知道我在哪里

在此处输入图片说明

and my Service.svc is: 而我的Service.svc是:

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

my web.config 我的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>

my IService.cs 我的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; }
    }

} }

my Service.svc.cs 我的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
}
}

I don't know where I am wrong, I have tried the answer of the following links but nothing works for me: 我不知道自己在哪里错,我尝试了以下链接的答案,但对我没有任何帮助:

If any one can help... 如果有人可以帮助...

The error denotes that the IIS is not able to find the type mobile.Service . 该错误表明IIS无法找到类型mobile.Service There could be many reasons why it is not able to find the type. 找不到类型的原因可能有很多。 I suggest you to specify the assembly name also in the service attribute. 建议您在服务属性中也指定程序集名称。

Also, you can check whether the assembly really contains the type by using ILDasm . 另外,您可以使用ILDasm检查程序集是否确实包含类型。

Update 更新

Try 尝试

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM