我正在尝试创建一个应用程序,可以在其中通过Web服务将数据插入数据库。我与ADO数据库的连接良好,但是当我尝试将信息从主应用程序发送到Web服务时,出现以下错误。
找不到引用合同的默认端点元素
ServiceModel客户端中的“ MathServiceReference.IMathService”
配置部分。这可能是因为没有配置文件
为您的应用程序找到,或者因为没有匹配的端点元素
该合同可以在client元素中找到。
我的主要应用
protected void btnMultiply_Click(object sender, EventArgs e)
{
ServiceReference1.MathServiceClient client = new ServiceReference1.MathServiceClient();
txtSvar.Text = client.Multiply(int.Parse(txtTal2.Text)).ToString();
}
我在Wwb服务中的课程
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/