【问题标题】:Could not find default endpoint element that references contract - Hosting wcf找不到引用合同的默认端点元素 - 托管 wcf
【发布时间】:2014-07-25 20:35:50
【问题描述】:

我在这个站点上有一个 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 文件夹中的 web.config:

<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>

我不确定我错在哪一部分。我的wcf体验才一个星期……

【问题讨论】:

    标签: c# winforms wcf hosting


    【解决方案1】:

    从库项目中的 app.config 复制 system.serviceModel 部分并将其放入 web.config 并刷新服务引用。另请参阅此答案。 Could not find default endpoint element

    【讨论】:

    • 当我设置address="wswob.somee.com" 或"wswob.somee.com/wobservice.svc" 时,服务不起作用...
    • 终于明白了!!!我设置绑定,然后设置客户端。合同应该是这样的:contract="com.somee.wobservice.Iwobservice"
    【解决方案2】:

    在您的 WCF 服务 web.config 文件中添加“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

    【讨论】:

    • 是的,这正是我所做的,但我没有使用 JSON……非常感谢
    • 它与 JSON 无关,但您尚未在 WCF 服务 web.config 文件中添加“wsHttpBinding”端点,这就是您面临错误的原因。
    【解决方案3】:

    在您的客户端 web.config 文件中添加客户端定义,如下所示;

     <system.serviceModel>
      /////
     <client>
             <endpoint  address="referencedurl"
              binding="webHttpBinding" bindingConfiguration=""
              contract="MemberService.IMemberService"
              name="MemberServiceEndPoint"
              behaviorConfiguration="Web">
          </endpoint>
     </client> 
    ////
     </system.serviceModel>
    

    AND 服务参考名称必须与接口前缀相同。 contract="ReferenceName.IMemberService"

    【讨论】:

      猜你喜欢
      • 2013-06-27
      • 2012-01-09
      • 2015-07-01
      • 2023-03-12
      • 2010-11-28
      • 2014-09-14
      • 2011-10-20
      相关资源
      最近更新 更多