WCF客户端配置问题

时间:2013-12-02 16:25:06

标签: wcf

我在VS2010中创建了一个返回Json的WCF服务。我还创建了一个Nunit测试项目,该项目调用服务的方法。使用内置的VS2010 Web服务器时,一切运行良好。然后我将服务配置为在我的本地IIS6.1中运行。我可以像http://localhost/PVSCService/WebData.svc一样在浏览器中成功启动服务,但我得到了名声:

  

http://localhost/PVSCService/WebData.svc没有可以接受该消息的端点。这通常是由错误的地址或SOAP操作引起的。有关更多详细信息,请参阅InnerException(如果存在)。

我的服务web.config:

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
  </system.web>
  <system.serviceModel>
    <services>
      <service name="PVSCWeb.Service.WebData">
        <endpoint name="jsonEP"
                  address=""
                  binding="webHttpBinding"
                  behaviorConfiguration="json"
                  contract="PVSCWeb.Service.IWebData"/>
      </service>
    </services>    
    <behaviors>
      <endpointBehaviors>
        <behavior name="json">
          <webHttp defaultOutgoingResponseFormat="Json"/>
        </behavior>
      </endpointBehaviors>      
      <serviceBehaviors>
        <behavior>
          <serviceMetadata httpGetEnabled="true"/>
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
 <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>

和我的Nunit测试项目app.config:

<configuration>
    <system.serviceModel>
      <bindings>
        <wsHttpBinding>
          <binding name="WSHttpBinding_IWebData" closeTimeout="00:01:00"
              openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
              bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
              maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
              messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
              allowCookies="false">
            <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
                maxBytesPerRead="4096" maxNameTableCharCount="16384" />
            <reliableSession ordered="true" inactivityTimeout="00:10:00"
                enabled="false" />
            <security mode="Message">
              <transport clientCredentialType="Windows" proxyCredentialType="None"
                  realm="" />
              <message clientCredentialType="Windows" negotiateServiceCredential="true"
                  algorithmSuite="Default" establishSecurityContext="true" />
            </security>
          </binding>
        </wsHttpBinding>
      </bindings>
      <client>
        <endpoint address="http://localhost/PVSCService/WebData.svc"
            binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IWebData"
            contract="ServiceReference1.IWebData" name="WSHttpBinding_IWebData">
          </endpoint>
      </client>
    </system.serviceModel>
  <system.diagnostics>
    <!-- This logging is great when WCF does not work. -->
    <sources>
      <source propagateActivity="true" name="System.ServiceModel" switchValue="Error, ActivityTracing">
        <listeners>
          <add name="AppFabricTracing" />
        </listeners>
      </source>
    </sources>
    <trace autoflush="true" />
    <sharedListeners>
      <add name="AppFabricTracing" initializeData="c:\PVSCService.svclog" type="System.Diagnostics.XmlWriterTraceListener" />
    </sharedListeners>
  </system.diagnostics>
</configuration>

我注意到有关关闭Windows防火墙的建议,但网络政策禁止这样做。我尝试添加正确的端点地址:

<endpoint name="jsonEP"
          address="http://localhost/PVSCService/WebData.svc"
          binding="webHttpBinding"
          behaviorConfiguration="json"
          contract="PVSCWeb.Service.IWebData"/>

但是这会产生关于多个站点绑定的另一个错误。似乎我错过了一些简单而又重要的东西。在此先感谢,任何帮助非常感谢。

1 个答案:

答案 0 :(得分:0)

好吧,您的WCF服务使用webHttpBinding,这是用于REST服务的服务。

但是,您的 NUnit 配置使用wsHttpBinding这里错误 - 这是 SOAP 绑定,而 NOT 与{兼容{1}}。您需要更改NUnit配置以使用webHttpBinding