找不到引用契约-托管wcf的默认端点元素
本文关键字:默认 端点 元素 wcf 托管 引用 契约 找不到 | 更新日期: 2023-09-27 18:06:52
我在这个网站上有一个wcf服务http://wswob.somee.com/wobservice.svc
我尝试用我的winform应用程序消费该服务。这是我收到的错误,当我创建一个即时的服务
com.somee.wobservice.IwobserviceClient myservice = new com.somee.wobservice.IwobserviceClient();
错误:Could not find default endpoint element that references contract
'com.somee.wobservice.Iwobservice' 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.
我搜索并修改了我的app.config文件:
<system.serviceModel>
<behaviors>
<endpointBehaviors>
<behavior name="wobservice">
<clientVia />
</behavior>
</endpointBehaviors>
</behaviors>
<client>
<endpoint
name="wobservice"
address="http://wswob.somee.com/wobservice.svc"
binding="webHttpBinding"
contract="com.somee.wobservice"
behaviorConfiguration="wobservice" />
</client>
</system.serviceModel>
</configuration>
还有我的网。在WCF文件夹中配置:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="Web">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true">
<baseAddressPrefixFilters>
<add prefix="http://wswob.somee.com/"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
<bindings>
<webHttpBinding>
<binding>
<security mode="None" />
</binding>
</webHttpBinding>
</bindings>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https"/>
<add binding="basicHttpBinding" scheme="http"/>
</protocolMapping>
<services>
<service name="wobwcf.wobservice">
<endpoint address=""
binding="webHttpBinding"
behaviorConfiguration="Web"
contract="wobwcf.Iwobservice" />
</service>
</services>
</system.serviceModel>
我不确定我哪部分写错了。
复制系统。从库项目的app.config中取出serviceModel部分,并将其放入web。配置并刷新服务引用。参见这个答案。找不到默认端点元素
在您的WCF服务web中添加"WSHttpBinding"端点。配置文件如下
<endpoint address="web" behaviorConfiguration="jsonBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="DataService.IDataService"/>
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" contract="DataService.IDataService" />
并在app.config文件中编写如下代码
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IDataService" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647">
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost/pricedataservice/DataService.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IDataService" contract="DataService.IDataService"
name="WSHttpBinding_IDataService" />
</client>
我相信这将解决你的问题,下面的博客将帮助你理解WCF服务中不同类型的绑定
http://www.dotnet-tricks.com/Tutorial/wcf/VE8a200713-Understanding-various-types-of-WCF-bindings.html在客户端web中添加客户端定义。配置文件如下;
<system.serviceModel>
/////
<client>
<endpoint address="referencedurl"
binding="webHttpBinding" bindingConfiguration=""
contract="MemberService.IMemberService"
name="MemberServiceEndPoint"
behaviorConfiguration="Web">
</endpoint>
</client>
////
</system.serviceModel>
AND服务引用名称必须与接口前缀相同。合同= " ReferenceName 。IMemberService "