WCF服务不完全正常工作和内部服务器错误

时间:2015-01-07 23:15:58

标签: c# asp.net wcf database-connection

我正在尝试创建一个WCF服务,人们可以在数据库中添加职位空缺,数据库显示在另一个webform中。

我的问题是,当我尝试显示我的网络表单时,我收到此错误:

  

服务器实习生错误:由于目标计算机拒绝连接,因此尚未建立连接。

     

描述:执行实际Web查询时发生了未处理的异常。

     

详细信息:System.Net.Sockets.SocketException不允许连接,因为目标计算机拒绝了它

     

来源:

     

[System.ComponentModel.EditorBrowsableAttribute(System.ComponentModel.EditorBrowsableState.Advanced)]       Service.GetAllJobsResponse Service.IService.GetAllJobs(Service.GetAllJobsRequest request){
      return base.Channel.GetAllJobs(request);       }

我的研究告诉我,可能是我的localhost刚改变了它的地址,但我检查了它,它也是一样的。然后我的讲师在我的电脑上花了1小时没有找到任何解决方案。也许它与我的WCF服务相关联,似乎有些不对劲。

我在这里张贴的错误图片可能有:

enter image description here

白色方块的转换:此操作无法由测试WCF客户端处理,因为该操作使用的是GetAllJobsResponse类型。

这是我的文件IService.cs中的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

// REMARQUE : vous pouvez utiliser la commande Renommer du menu Refactoriser pour changer le nom d'interface "IService" à la fois dans le code et le fichier de configuration.
[ServiceContract]
public interface IService
{
    [OperationContract]
    void DoWork();

    [OperationContract]
    DataSet.TableDataTable GetAllJobs();

    [OperationContract]
    DataSet.TableDataTable GetAJobs(int ID);

    [OperationContract]
    void AddJob(string title, string salary, string benefits, string keywords, string jobtype, string location, DateTime startDate, string description, string recruitmentAgency, string agencyContact, string agencyTel, string agencyEmail, string jobRef, DateTime datePosted, DateTime dateExpire);

    [OperationContract]
    DataSet.Table1DataTable testJobs();

}

以下是我的文件Service.cs的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;

// REMARQUE : vous pouvez utiliser la commande Renommer du menu Refactoriser pour changer le nom de classe "Service" à la fois dans le code, le fichier svc et le fichier de configuration.
public class Service : IService
{
    public void DoWork()
    {
        throw new NotImplementedException();
    }

    public DataSet.TableDataTable GetAllJobs()
    {
        DataSetTableAdapters.TableTableAdapter ta = new DataSetTableAdapters.TableTableAdapter();
        return ta.GetData();    
    }

    public DataSet.TableDataTable GetAJobs(int ID)
    {
       DataSetTableAdapters.TableTableAdapter ta = new DataSetTableAdapters.TableTableAdapter();
       return ta.GetDataByID(ID);    
    }

    public void AddJob(string title, string salary, string benefits, string keywords, string jobtype, string location, DateTime startDate, string description, string recruitmentAgency, string agencyContact, string agencyTel, string agencyEmail, string jobRef, DateTime datePosted, DateTime dateExpire)
    {
            DataSetTableAdapters.TableTableAdapter ta = new DataSetTableAdapters.TableTableAdapter();
            ta.Insert(title, salary, benefits, keywords, jobtype, location, startDate, description, recruitmentAgency, agencyContact, agencyTel, agencyEmail, jobRef, datePosted, dateExpire);
    }

    public DataSet.Table1DataTable testJobs()
    {
        DataSetTableAdapters.Table1TableAdapter ta = new DataSetTableAdapters.Table1TableAdapter();
        return ta.GetAllData();
    }
}

如果您需要任何其他代码(web.configwebform.apsx.cs或数据库,请告诉我们。 希望你能提供帮助。

编辑: 这是我的网络服务' web.config' :

<?xml version="1.0"?>
<!--
  Pour plus d'informations sur la configuration de votre application ASP.NET, consultez
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <connectionStrings>
    <add name="DatabaseConnectionString" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True" providerName="System.Data.SqlClient"/>
  </connectionStrings>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
          <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  </system.serviceModel>
  <!-- <endpoint address="http://localhost:43988/Service.svc" binding="basicHttpBinding" bindingConfiguration="countrySoap" contract="ServCountry.countrySoap" name="countrySoap"/> -->
</configuration>

我在这里发布了我的webform&#39; web.config&#39; :

<?xml version="1.0"?>
<!--
  Pour plus d'informations sur la configuration de votre application ASP.NET, consultez
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.5"/>
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <appSettings/>
  <system.serviceModel>
    <bindings>
      <basicHttpBinding>
        <binding name="BasicHttpBinding_IService" />
      </basicHttpBinding>
    </bindings>
    <client>
      <endpoint address="http://localhost:43988/Service.svc" binding="basicHttpBinding"
        bindingConfiguration="BasicHttpBinding_IService" contract="Service.IService"
        name="BasicHttpBinding_IService" />
    </client>
  </system.serviceModel>
</configuration>
<!--wcf web service : http://localhost:45317/ -->

如果您还需要其他代码,请询问 Mayeul

0 个答案:

没有答案
相关问题