.net WCF:Can';不要调用自己的WCF服务
我有我的WCF服务,我已经从MSTest项目创建了对它的引用。下面是我调用服务方法的示例:.net WCF:Can';不要调用自己的WCF服务,.net,wcf,wcfserviceclient,.net,Wcf,Wcfserviceclient,我有我的WCF服务,我已经从MSTest项目创建了对它的引用。下面是我调用服务方法的示例: IEnrollmentService serviceClient = ChannelFactory<IEnrollmentService> .CreateChannel(new BasicHttpBinding(), new EndpointAddress("http://localhost/EnrollmentService.svc")); P
IEnrollmentService serviceClient = ChannelFactory<IEnrollmentService>
.CreateChannel(new BasicHttpBinding(),
new EndpointAddress("http://localhost/EnrollmentService.svc"));
PublishResult res = serviceClient.PublishEnrollmentProfile(...);
这将返回另一个错误:
找不到具有的终结点元素
名称
''
和合同
'EnrollmentServiceReference.IEnrollmentService'
在ServiceModel客户端中
配置部分。这可能是
因为没有配置文件
为您的应用程序找到,或因为
没有与此名称匹配的端点元素
在客户端元素中找不到
问题1:
实例化wcf服务客户端的正确方法是什么
问题2:
我的情况怎么了
非常感谢
另外,关于我可以使用WcfTestClient连接到服务的一些问题,更多详细信息如下:
p.p.S.以下是服务器端WCF服务配置:
<system.serviceModel>
<services>
<service name="McActivationApp.EnrollmentService" behaviorConfiguration="McActivationApp.EnrollmentServicBehavior">
<endpoint address="" binding="webHttpBinding" contract="McActivationApp.IEnrollmentService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="McActivationApp.IEnrollmentService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="McActivationApp.EnrollmentServicBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>
您的问题在于:您的服务配置定义了
webHttpBinding
端点-这是一个REST(“HTTP上的Xml”)端点
但是,您的客户机使用basichttppbinding
,这是一个SOAP绑定-它们是不兼容的
您需要对此进行更改,以确保服务端提供的服务端点能够让客户端连接到服务端
因此:
- 使用
将另一个端点添加到您的服务配置中,并连接到该端点basicHttpBinding
- 将客户端更改为使用
webHttpBinding
)-而不是提供的URL。。。并没有构造函数只接收服务URL。是的,第二种方式(当端点名称用作构造函数参数时)也可以工作。。。早些时候,它表明URI有问题。。。谢谢!
<system.serviceModel>
<services>
<service name="McActivationApp.EnrollmentService" behaviorConfiguration="McActivationApp.EnrollmentServicBehavior">
<endpoint address="" binding="webHttpBinding" contract="McActivationApp.IEnrollmentService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="McActivationApp.IEnrollmentService" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="McActivationApp.EnrollmentServicBehavior">
<serviceMetadata httpGetEnabled="True"/>
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>