简体   繁体   中英

No endpoint on cosume webservice application

I am learning to create a WCF service. I tested my service that is worked when I tested it using SoapUi. Now I am creating a testing website to add this service as service reference. When I call the method of the service, I got the error "Could not find default endpoint element that references contract". I searched the web and still no idea to fix it. Would someone help me what I should do or show me the example code. Thanks.

There is my service config:

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

The code in the client app:

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

According to your description and code details, It seems that you want to invoke the WCF Service by adding service reference, you need to add WebHttpBehavior to the client endpoint.
You could refer to the following code.

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

Feel free to let me know if there is anything I can help with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM