2012-12-09 124 views
2

我试图创建一个应用程序,我可以通过Web服务将数据插入到数据库中。我有一个很好的连接到我的ADO数据库,但是当我尝试从我的主要应用程序发送信息到我的Web服务时,出现以下错误。通过WCF Web服务将数据设置到ADO数据库

找不到默认终结点元素,在ServiceModel客户 配置部分引用合同 “MathServiceReference.IMathService”。这可能是因为没有为您的应用程序找到配置文件 ,或者因为没有匹配 此协议可以在客户端元素中找到的端点元素。

我的主要应用

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> 
+0

显示你是WCF客户端配置。 – abatishchev

+0

我现在把它添加到我的问题 – TheZozoOwner

回答

3

你的WCF的配置没有终点,至少一个,例如:

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

这还需要与消费应用程序中'client'元素内的端点一起镜像。应该在创建代理时创建,但如果现在添加它,并且不想重新创建代理,则可以手动添加代理。 –

+0

我添加了终点以上下system.serviceModel,我也得到了同样的错误,这里是我的applikation终点客户端下 <端点地址=“HTTP://本地主机:53197/MathService.svc”结合= “basicHttpBinding的” bindingConfiguration = “BasicHttpBinding_IMathService” 合同= “ServiceReference1.IMathService” 名称= “BasicHttpBinding_IMathService”/> TheZozoOwner

+0

@AliRiyadh:请后得到的用于服务器和客户端配置。你还需要添加mex端点吗?这是一个元数据端点,可以更轻松地发现,以便您可以通过浏览器或测试客户端测试您的服务(在VS文件夹下找到WcfTestClient.exe)。 – abatishchev

-1

请参见下面的代码示例:

var jokeService = new JokeOfTheDayServiceClient(); 
jokeService.GetJokeCompleted += (s,e) =< jokeService_GetJokeCompleted; 

private void jokeService_GetJokeCompleted(object sender, GetJokeCompletedEventArgs e) 
{ 
    if (!e.Cancelled) 
    { 
     jokeTextBlock.Text = e.Result; 
    } 
} 

看来你的问题是你需要在客户端完成通信时调用“Completed”函数。如果您尝试直接访问网络,网络可能尚未完成信息传递。

+0

非常有趣,但没有帮助 – TheZozoOwner