服务在WCF中找不到其他服务的端点
本文关键字:服务 端点 其他 WCF 找不到 | 更新日期: 2023-09-27 18:18:35
我正在尝试创建两个应该能够相互访问的WCF服务。然而,我得到这个错误信息:服务器在处理请求时遇到错误。异常消息是"找不到引用契约的默认端点元素"AddonWCFService。在ServiceModel客户端配置部分中的IService1'。这可能是因为没有找到您的应用程序的配置文件,或者因为在客户端元素中没有找到与此契约匹配的端点元素。
我从这个服务中调用Test()方法
namespace CustomersService
{
[ServiceContract]
public interface ICustomers
{
[OperationContract]
[WebGet]
string Test();
}
public class Customers : ICustomers
{
private int m_i = 0;
public int GetCounter()
{
return m_i;
}
public void Test()
{
AddonWCFService.Service1Client foo = new AddonWCFService.Service1Client();
}
}
}
其他服务
namespace AddonWCFWebservice
{
[ServiceContract]
public interface IService1
{
[OperationContract]
void Init();
}
public class Service1 : IService1
{
public void Init()
{
}
}
}
我webconfig :
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service behaviorConfiguration="MyserviceBehavior" name="CustomersService.Customers">
<endpoint name="ws" address="ws" binding="wsHttpBinding" contract="CustomersService.ICustomers"/>
<endpoint name=""
address=""
binding="webHttpBinding"
contract="CustomersService.ICustomers"
behaviorConfiguration="WebBehavior"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<service name="AddonWCFWebservice.Service1" behaviorConfiguration="MyserviceBehavior">
<endpoint address="" binding="wsHttpBinding" contract="AddonWCFWebservice.IService1"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyserviceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
<customErrors mode="Off"/>
</system.web>
</configuration>
两个服务驻留在IIS的同一个活动目录中。我使用web URL(即http://www.foobar.baz/Test/Service1.svc和http://www.foobar.baz/Test/Customers.svc
)将服务引用添加到VS c#项目中。这可能是显而易见的,但我对整个WCF业务相当陌生。谢谢!
Update:解决方案是在我的webconfig中添加一个客户端部分。我还使用了basicHttpBinding而不是wsHttpBinding,因为我的安全性将被合并到其他地方,因为它是一个公共服务。我必须匹配客户端的绑定和服务部分的绑定:两者都是basicHttpBinding
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<client>
<endpoint
name=""
address="http://demo.mydomain.baz/TestService/Service1.svc"
binding="basicHttpBinding"
contract="AddonWCFService.IService1" />
</client>
<services>
<service behaviorConfiguration="MyserviceBehavior" name="CustomersService.Customers">
<endpoint name="ws" address="ws" binding="wsHttpBinding" contract="CustomersService.ICustomers"/>
<endpoint name=""
address=""
binding="webHttpBinding"
contract="CustomersService.ICustomers"
behaviorConfiguration="WebBehavior"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
<service name="AddonWCFWebservice.Service1" behaviorConfiguration="MyserviceBehavior">
<endpoint address="" binding="basicHttpBinding" contract="AddonWCFWebservice.IService1"/>
<!--
<endpoint address=""
binding="webHttpBinding"
contract="AddonWCFWebservice.IService1"
behaviorConfiguration="WebBehavior"/>
-->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyserviceBehavior">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebBehavior">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.web>
<compilation debug="true"/>
<customErrors mode="Off"/>
</system.web>
</configuration>
配置的问题是您没有客户端配置。您只有服务器部件。您需要具有带有端点的客户端元素。看看这里:http://msdn.microsoft.com/en-us/library/ms731745.aspx
如果你不确定你的配置技能,我会建议你用SvcConfigEditor.exe打开你的配置。您将立即看到配置的内容。你可以在这里找到它:C:'Program Files'Microsoft sdk 'Windows'v6.0A'Bin'SvcConfigEditor.exe。如果您这样做-您将看到没有配置的客户端
我想你在配置文件中指定了错误的服务契约。
这一行:
<endpoint address="" binding="wsHttpBinding" contract="AddonWCFWebservice.IService1"/>
将合约指定为"AddonWCFWebservice"。当它应该是类似于"AddonService。IService1"(不含"WCF")。