简体   繁体   中英

WCF service reference not including binding and client endpoint

I'm following this answer from a different question, trying to get my WCF service to only handle GET requests. I've added the [WebGet] to my operation, added an endpoint behavior with the <webHttp /> , changed my default endpoint to use said behavior, and changed the default endpoint's binding to webHttpBinding .

web.config's system.servicemodel looks like:

<system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="">
            <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
            <serviceDebug includeExceptionDetailInFaults="false" />
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="webBehavior">
          <webHttp />
        </behavior>
      </endpointBehaviors>
  </behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true"
    multipleSiteBindingsEnabled="true" />

  <services>
    <service name="TestServiceLibrary.TestService">
      <endpoint behaviorConfiguration="webBehavior"
         address=""
         binding="webHttpBinding"
         contract="TestServiceLibrary.ITestService" />
      <endpoint 
         address="mex" 
         binding="mexHttpBinding" 
         contract="IMetadataExchange" />
    </service>
  </services>
</system.serviceModel>

This makes my service callable like: TestService.svc/GetData?value=x and that works great. Now I want to add a Service Reference to a client project. When I do that, the client project's app.config file does not get the binding and client endpoint configured. If I remove my behavior webBehavior above, change the default endpoint binding back to wsHttpBinding , and re-add the client's service reference - the client binding and endpoint are added successfully but I've lost GET support.

I realize I could leave the default endpoint using wsHttpBinding and add an endpoint with a different address set to binding webHttpBinding and a behavior with <webHttp /> , but I would really like the client app to be using GET.

EDIT:

I'm also interested in why the config fails to update in this situation. I'm wanting to allow consumption of this service to be low-friction (add the service reference through visual studio and then start making calls), so manually setting up the client config file is not ideal.

Try this configuration below. I have not tested it but it should work fine. Also, I would suggest to make the client yourself using this example . Note that ISampleService interface (in your case TestServiceLibrary.ITestService ) and all datacontracts that are referenced by this interface should be in separate assembly which is referenced as dll by service and client.

<system.serviceModel>
    <client>
        <endpoint behaviorConfiguration="webBehavior" address="url_to_TestService.svc" binding="webHttpBinding" contract="TestServiceLibrary.ITestService" />
    </client>
    <behaviors>
        <endpointBehaviors>
            <behavior name="webBehavior">
                <webHttp />
            </behavior>
        </endpointBehaviors>
    </behaviors>
</system.serviceModel>

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