我正在尝试创建一个可以通过 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/