在IIS上托管第一个WCF服务

时间:2015-03-04 13:48:53

标签: c# .net wcf iis

我在IIS上托管了一个可以正常工作的网站。

在Visual Studio中,我的项目称为Geomaps。它包含一个工作正常的网页,也是一个wcf Web服务。

我的开发机器上的本地Web服务工作正常,但我试图在远程IIS服务器上托管它。

我不知道如何设置它我尝试了各种配置。 Geomaps中的web.config是:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.web>
        <compilation debug="true" targetFramework="4.0" />
    </system.web>
    <system.serviceModel>
        <services>
            <service name="Service1"
                     behaviorConfiguration="MEX">
                <endpoint
                    address="http://150.158.0.87:8000/MEX"
                    behaviorConfiguration="CountryProvinceBehavior"
                    binding="webHttpBinding"
                    contract="IMetadataExchange" />
            </service>
        </services>
        <behaviors>
            <serviceBehaviors>
                <behavior name="CommentSessionIDBehavior">
                    <serviceMetadata httpGetEnabled="true"/>
                    <serviceDebug includeExceptionDetailInFaults="true"/>
                </behavior>
            </serviceBehaviors>
            <endpointBehaviors>
                <behavior name="MEX">
                    <serviceMetadata/>
                </behavior>
            </endpointBeahaviors>
        </behaviors>
    </system.serviceModel>
    <system.webServer>
        <modules runAllManagedModulesForAllRequests="true" />
    </system.webServer>
</configuration>

有人可以帮助我。我正在解决以下错误:

  

无法添加&#39; serviceMetadata&#39;行为延伸到&#39; MEX&#39;端点行为,因为基础行为类型未实现IEndpointBehavior接口

1 个答案:

答案 0 :(得分:0)

尝试这样的事情:

<system.serviceModel>
  <services>
    <service name="Service1" behaviorConfiguration="MyMexServiceBehavior">
      <endpoint address="http://150.158.0.87:8000"
                binding="basicHttpBinding"
                bindingConfiguration="BasicHttpEndpointBinding"
                contract="MyNamespace.MyIService">
      </endpoint>
      <endpoint address="mex"
                binding="mexHttpBinding"
                contract="IMetadataExchange" />
    </service>
  </services>
  <behaviors>
    <serviceBehaviors>
      <basicHttpBinding>
        <binding name="BasicHttpEndpointBinding"
           maxBufferSize="9000000"
           maxReceivedMessageSize="9000000">
          <security mode = "None" />
        </binding>
      </basicHttpBinding>
      <behavior name="MyMexServiceBehavior">
        <serviceMetadata httpGetEnabled="true"
                         httpGetUrl="http://150.158.0.87:8000/MEX"
                         httpsGetEnabled="false"/>
        <serviceDebug includeExceptionDetailInFaults="true" />
      </behavior>
    </serviceBehaviors>
    <endpointBehaviors>
      <behavior name="MEX">
        <serviceMetadata/>
      </behavior>
    </endpointBehaviors>
  </behaviors>
</system.serviceModel>