2011-09-07 77 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");)。

相关问题