c# - 通过 WCF Web 服务将数据设置到 ADO 数据库

标签 c# wcf exception insert ado.net

我正在尝试创建一个可以通过 Web 服务将数据插入数据库的应用程序。我与 ADO 数据库的连接良好,但是当我尝试将信息从主应用程序发送到 Web 服务时,出现以下错误。

Could not find default endpoint element that references contract 'MathServiceReference.IMathService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.

我的主要应用

protected void btnMultiply_Click(object sender, EventArgs e)
{
    ServiceReference1.MathServiceClient client = new ServiceReference1.MathServiceClient();
    txtSvar.Text = client.Multiply(int.Parse(txtTal2.Text)).ToString();
}

我的 Wwb 服务中的类(class)

public int Multiply(int box2)
{
    if (box2 == null)
    {
        return 1;
    }
    else
    {
        koppling db = new koppling();
        var testet = new tests();
        testet.namn = box2.ToString();
        db.tests1.AddObject(testet);
        db.SaveChanges();
        return 2;
    }
}

我的 WCF 配置:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true" />
  </system.webServer>
</configuration>

最佳答案

您的 WCF 配置缺少端点,至少一个,例如:

<system.serviceModel>
    <services>
        <service name="MathService">
            <endpoint binding="netTcpBinding" contract="MathServiceReference.IMathService" />
        </service>
    </services>
</system.serviceModel>

关于c# - 通过 WCF Web 服务将数据设置到 ADO 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13784075/

相关文章:

.net - 如何以编程方式配置 WCF 已知类型?

java - 计算java中的递归步骤

django - 如何关闭 Sentry Web UI 异常跟踪中的变量缩短?

c# - 是否可以卸载在 dotnet 核心中动态加载的程序集?

C# WPF 页面间导航( View )

c# - 被 OverflowException 击中

c# - 如何仅在同一用户的登录 session 中使用 WCF NetNamedPipesBinding 进行进程间通信?

c# - 如何在 ASP.NET Core 1 和 VSCode 编辑器中使用 WCF 服务?

python - 在 python 中处理断言

c# - 使用 DotNetOpenAuth 设置带有子域标识符的 OpenID 提供程序