2011-09-07 25 views
0

我試圖通過修改app.config將我的WCF服務從TCP綁定切換到HTTP綁定,但是當我嘗試從測試控制檯使用WCF服務時應用程序中,我得到這個錯誤:使用服務時出錯:「找不到引用合同的默認端點元素」

Could not find default endpoint element that references contract 'ServiceReference1.IUsers' 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.

下面是使用HTTP綁定的新的app.config,讓我上面的錯誤:

<services> 
    <service name="Test.UserServ" behaviorConfiguration="ServiceBehavior"> 
    <host> 
     <baseAddresses> 
     <add baseAddress="http://localhost:8000/Users" /> 
     </baseAddresses> 
    </host> 
    <endpoint 
     address="" 
     binding="webHttpBinding" behaviorConfiguration="EndpointBehavior" 
     contract="Test.IUsers" /> 
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" /> 
    </service> 
</services> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="ServiceBehavior"> 
     <serviceMetadata httpGetEnabled="true" /> 
    </behavior> 
    </serviceBehaviors> 
    <endpointBehaviors> 
    <behavior name="EndpointBehavior"> 
     <webHttp /> 
    </behavior> 
    </endpointBehaviors> 
</behaviors> 

這裏是一個仍然使用TCP綁定舊工作的app.config:

<services> 
    <service name="Test.UserServ" behaviorConfiguration="TCPBehavior"> 
    <host> 
     <baseAddresses> 
     <add baseAddress="net.tcp://localhost:8731/Users"/> 
     </baseAddresses> 
    </host> 
    <endpoint 
     address="" 
     binding="netTcpBinding" bindingConfiguration="TCPConfiguration" 
     contract="Test.IUsers"/> 
    <endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/> 
    </service> 
</services> 
<bindings> 
    <netTcpBinding> 
    <binding name="TCPConfiguration"> 
     <security mode="None"/> 
    </binding> 
    </netTcpBinding> 
</bindings> 
<behaviors> 
    <serviceBehaviors> 
    <behavior name="TCPBehavior"> 
     <serviceMetadata/> 
    </behavior> 
    </serviceBehaviors> 
</behaviors> 

配置出了什麼問題,或者是由於我切換到的HTTP綁定強加的某些限制?

+0

錯誤信息中提到的合同「ServiceReference1.IFile」在哪裏?我沒有看到你的配置中任何地方的任何服務合同的痕跡(無論是舊的還是新的)。您的測試應用的配置是否引用了錯誤的網址,或許? –

+0

@marc_s:這只是一個錯字。我也有一些其他服務,所有的配置完全相同。我的示例中的實際錯誤消息引用了'ServiceReference1.IUser'。感謝您指出了這一點。至於網址,我確定測試應用引用的是正確的。 – rafale

+1

什麼是WsHttpMtomBinding? –

回答

0

最有可能您的客戶端配置文件指定兩個端點。舊的TCP端點和新的HTTP端點。在您的客戶端配置文件中刪除舊的TCP端點,或者在您的代碼中聲明客戶端時使用構造函數(構造函數將端點的名稱視爲字符串,如new YourClient("NameOfWsHttpBinding");)。

相關問題