2012-12-09 119 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