Cosume Web服务应用程序上没有端点

时间:2018-11-09 14:48:15

标签: c# visual-studio wcf

我正在学习创建WCF服务。我测试了使用SoapUi进行测试时可以使用的服务。现在,我正在创建一个测试网站,以将该服务添加为服务参考。当我调用服务的方法时,出现错误“找不到引用合同的默认端点元素”。我搜索了网络,但仍然不知道要修复它。会有人帮助我该做什么或向我展示示例代码。谢谢。

有我的服务配置:

 <system.web>
   <compilation debug="true" targetFramework="4.5.2" />
   <authentication mode="Windows"/>
   <httpRuntime targetFramework="4.5.2"/>
 </system.web>
 <system.serviceModel>
    <services>
      <service behaviorConfiguration="ServiceBehaviour" name="Order.IOrders">
        <endpoint address="" binding="webHttpBinding"  contract="Order.IOrders" behaviorConfiguration="web">
        </endpoint>
      </service>
    </services>

    <behaviors>
       <serviceBehaviors>
        <behavior name="ServiceBehaviour">
        <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
        <serviceMetadata httpGetEnabled="true" httpsGetEnabled="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="web">
      <webHttp/>
    </behavior>
  </endpointBehaviors>
</behaviors>
<protocolMapping>
    <add binding="basicHttpsBinding" scheme="https"  />
 </protocolMapping>    
 <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  <client>
  <endpoint
      name=""
      address="http://localhost:59837/Order.svc"
      binding="basicHttpBinding"
      contract="Order.IOrders" />
</client>
 </system.serviceModel>
 <system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
  <!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
  -->
   <directoryBrowse enabled="true"/>
</system.webServer>

客户端应用中的代码:

 ServiceReference1.OrdersClient client = new ServiceReference1.OrdersClient();          
        client.checkOrderNumber(txtNum.Text.ToString());
    }

1 个答案:

答案 0 :(得分:0)

根据您的描述和代码详细信息,似乎您想通过添加服务引用来调用WCF服务,您需要向客户端端点添加 WebHttpBehavior
您可以参考以下代码。

    <system.serviceModel>
      <behaviors>
        <endpointBehaviors>
          <behavior name="webEndpoint">
            <webHttp defaultBodyStyle="Wrapped"
                     defaultOutgoingResponseFormat="Xml"
                     helpEnabled="true"/>
          </behavior>
        </endpointBehaviors>
      </behaviors>
      <client>
        <endpoint name="myclient" address="http://localhost:9001/Service1.svc" binding="webHttpBinding" contract="ServiceReference1.IService1" behaviorConfiguration="webEndpoint"></endpoint>
      </client>
</system.serviceModel>

请随时告诉我是否有什么可以帮忙的。