Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# WCF配置_C#_Asp.net_Wcf_Configuration - Fatal编程技术网

C# WCF配置

C# WCF配置,c#,asp.net,wcf,configuration,C#,Asp.net,Wcf,Configuration,我正在阅读一本有关WCF的REST服务书籍。我一直在遵循这些示例,并重申WCF的配置似乎很难掌握。我在下面有一段代码,配置并打开一个端点。我知道这是一种老式的3.0方式来完成这个RESTful任务,但我想知道我如何在应用程序配置中设置它,而不是任何想法?还有谁知道有哪个站点以合理的方式在代码/配置中分解WCF配置?我一直在寻找的大多数地方只展示了具体的例子 CustomBinding b = new CustomBinding(); TextMessageEnco

我正在阅读一本有关WCF的REST服务书籍。我一直在遵循这些示例,并重申WCF的配置似乎很难掌握。我在下面有一段代码,配置并打开一个端点。我知道这是一种老式的3.0方式来完成这个RESTful任务,但我想知道我如何在应用程序配置中设置它,而不是任何想法?还有谁知道有哪个站点以合理的方式在代码/配置中分解WCF配置?我一直在寻找的大多数地方只展示了具体的例子

        CustomBinding b = new CustomBinding();
        TextMessageEncodingBindingElement msgEncoder = new TextMessageEncodingBindingElement();
        msgEncoder.MessageVersion = MessageVersion.None;
        b.Elements.Add(msgEncoder);
        HttpTransportBindingElement http = new HttpTransportBindingElement();
        b.Elements.Add(http);
        ServiceHost sh = new ServiceHost(typeof(SimpleHTTPService));
        ServiceEndpoint se = sh.AddServiceEndpoint(typeof(SimpleHTTPService),
        b,
        "http://localhost:8889/TestHttp");
        sh.Open();

如果您想在配置中定义该端点,它将类似于下面的配置。请注意,这还不足以模拟3.0中的REST编程模型(请记住,这只设置绑定;在3.5及更高版本中,您只需要设置一个行为)



WCF 4允许您在不使用上述代码的情况下执行此操作,也不必像上面所说的那样干扰web/app.config。。。我知道这是一种老式的3.0方式来完成这个RESTful任务,但我想知道我如何在app config中设置它,而不是在app config中。谢谢Carlos,你能告诉我为什么我需要设置一个行为吗?我们在这里讨论的是服务/enpoint行为还是两者都有?这将是端点行为。WCF/.NET3.0中对非SOAP端点的支持非常糟糕。你不能用3.5吗?如果可以使用它,那么就可以为端点使用
端点行为。
<system.serviceModel>
  <bindings>
    <customBinding>
      <binding name="OldStylePox">
        <textMessageEncoding messageVersion="None" />
        <httpTransport />
      </binding>
    </customBinding>
  </bindings>
  <services>
    <service name="USE_THE_FULLY_QUALIFIED_NAME_OF_SimpleHttpService">
      <endpoint address="http://localhost:8889/TestHttp"
                binding="customBinding"
                bindingConfiguration="OldStylePox"
                contract="USE_THE_FULLY_QUALIFIED_NAME_OF_SimpleHttpService" />
    </service>
  </services>
<system.serviceModel>