简体   繁体   English

WCF服务参考不包括绑定和客户端端点

[英]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. 我正在从另一个问题中获得答案 ,试图使我的WCF服务仅处理GET请求。 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 . 我已经将[WebGet]添加到了操作中,并使用<webHttp />添加了端点行为,将默认端点更改为使用上述行为,并将默认端点的绑定更改为webHttpBinding

web.config's system.servicemodel looks like: web.config的system.servicemodel看起来像:

<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. 这使我的服务可以调用,例如: TestService.svc/GetData?value=x ,效果很好。 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. 当我这样做时,客户端项目的app.config文件未获取绑定和客户端端点的配置。 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. 如果删除上面的行为webBehavior ,请将默认的终结点绑定更改回wsHttpBinding ,然后重新添加客户端的服务引用-成功添加了客户端绑定和终结点,但是我失去了GET支持。

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. 我意识到我可以使用wsHttpBinding保留默认终结点,并添加一个设置了不同地址的终结点来绑定webHttpBinding并使用<webHttp />进行行为,但是我真的希望客户端应用程序使用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. 我想让这项服务的使用量降低(通过Visual Studio添加服务参考,然后开始进行调用),因此手动设置客户端配置文件不是理想的选择。

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. 请注意, ISampleService接口(在您的情况下为TestServiceLibrary.ITestService )和此接口引用的所有数据合同应放在单独的程序集中,服务和客户端均将其引用为dll。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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