C# 找不到引用承载合同的wcf的默认终结点元素

C# 找不到引用承载合同的wcf的默认终结点元素,c#,winforms,wcf,hosting,C#,Winforms,Wcf,Hosting,我在这个网站上有一个wcf服务 我尝试使用winform应用程序使用该服务。这是我在创建即时服务时收到的错误 com.somee.wobservice.IwobserviceClient myservice = new com.somee.wobservice.IwobserviceClient(); 错误: Could not find default endpoint element that references contract 'com.somee.wobservice.Iwobse

我在这个网站上有一个wcf服务

我尝试使用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文件夹中的my 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的体验只有一周…

从库项目的app.config复制system.serviceModel部分,将其放入web.config并刷新服务参考。请参见此答案

在WCF service web.config文件中添加“WSHttpBinding”端点,如下所示

 <endpoint address="web" behaviorConfiguration="jsonBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="DataService.IDataService"/>
 <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" contract="DataService.IDataService"  />
<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>

在app.config文件中编写如下代码

 <endpoint address="web" behaviorConfiguration="jsonBehavior" binding="webHttpBinding" bindingConfiguration="webHttpBindingWithJsonP" contract="DataService.IDataService"/>
 <endpoint address="" binding="wsHttpBinding" bindingConfiguration="wsHttpBinding" contract="DataService.IDataService"  />
<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服务中不同类型的绑定


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

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

/////
////

和服务引用名称必须与接口前缀相同。contract=“ReferenceName.IMemberService”

当我设置address=”“或“”时,服务没有工作…最后我得到了它!!!我设置绑定,然后设置客户端。合同应该是这样的:contract=“com.somee.wobservice.Iwobservice”是的,这正是我所做的,但我没有使用JSON。。。感谢一个与JSON无关的文件,但是您没有在WCF服务web.config文件中添加“wsHttpBinding”端点,这就是您面临错误的原因。