Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF服务未完全工作,内部服务器错误_C#_Asp.net_Wcf_Database Connection - Fatal编程技术网

C# WCF服务未完全工作,内部服务器错误

C# WCF服务未完全工作,内部服务器错误,c#,asp.net,wcf,database-connection,C#,Asp.net,Wcf,Database Connection,我正在尝试创建一个WCF服务,人们可以在数据库中添加职位空缺,该数据库显示在另一个Web表单中 我的问题是,当我试图显示我的webform时,会出现以下错误: 服务器实习生错误:由于目标计算机拒绝连接,因此尚未建立连接 描述:执行实际web查询时发生未处理的异常 详细信息:System.Net.Sockets.SocketException不允许连接,因为目标计算机拒绝了它 资料来源: [System.ComponentModel.EditorBrowsBalAttribute(System.C

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

我的问题是,当我试图显示我的webform时,会出现以下错误:

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

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

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

资料来源:

[System.ComponentModel.EditorBrowsBalAttribute(System.ComponentModel.EditorBrowsBalState.Advanced)] Service.GetAllJobsResponse Service.IService.GetAllJobs(Service.GetAllJobsRequest请求){
返回base.Channel.GetAllJobs(请求); }

我的研究告诉我,可能是我的本地主机刚刚更改了地址,但我检查了一下,结果是一样的。然后我的讲师花了1小时在我的电脑上,没有找到任何解决方案。也许它与我的WCF服务有关,它似乎有问题

我在这里发布了错误的图片,可能有:

白色方块的转换:测试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.config
webform.apsx.cs
或数据库,请告诉我)。 希望你能帮忙

编辑: 这是我的web服务“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>

我在这里发布我的web表单“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>
  <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

很可能客户端和主机之间的配置(端点、绑定)不匹配。向我们展示两个配置的ServiceModel部分。我已经输入了我的2个网络配置的代码。你所说的服务模型是什么意思?是.svc文件吗?ServiceModel指的是配置文件中的元素。我认为您的配置应该可以工作,您没有定义服务端点,但在这种情况下它将设置默认的basisHttpBinding。在客户端尝试发出请求之前,请确保您的WCF主机正在运行。我的一个朋友告诉我,当他不在IIS上运行时,解决了GetAllJobsResponse类型问题。但我还没有找到如何在VisualIntern服务器上启动它(我认为这是第二种选择)。WCF测试客户端无法处理接收复杂类型的问题,IIS没有问题。您需要启动主机(wcf服务),然后启动客户端网站。它们不能同时在同一端口上运行,因此请确保它们在不同的端口上。