2

如果我尝试将服务引用添加到我的空白 Windows 8 应用程序,我会收到以下两个警告/错误。

TransportSecurityBindingElement

该服务是一个带有 ServiceName.svc 文件的 wcf 服务,我见过一些带有 ServiceName.asmx 的服务。这是原因吗?我需要带有 *.asmx 文件的服务吗?

我真的很困惑,因为互联网上有太多关于这个话题的东西。同样令人困惑的是,它说 System.ServiceModel.Channels.TransportSecurityBindingElement 不受支持,但我从未使用过它。不在 web.config 或作为服务配置的代码中。

这是我在 web.config 中的服务配置:

<system.web>
  <compilation targetFramework="4.5" debug="true"/>
  <httpRuntime/>
  <pages controlRenderingCompatibilityVersion="3.5" clientIDMode="AutoID"/>
</system.web>
<system.serviceModel>
<diagnostics>
  <messageLogging logMalformedMessages="true" logMessagesAtServiceLevel="true" logMessagesAtTransportLevel="true"/>
</diagnostics>
<client/>
<services>
  <service behaviorConfiguration="basicHttpBehavior" name="e3kConnector.E3KConnectorService">
    <endpoint 
      address="mex" 
      binding="mexHttpBinding" 
      contract="IMetadataExchange" />
    <endpoint 
      address="" 
      binding="wsHttpBinding" 
      bindingConfiguration="wsHttpBinding"
      name="wsHttpEndpoint" 
      bindingName="" 
      contract="Service.MyService" />
    <endpoint 
      address="Soap" 
      binding="basicHttpBinding"
      bindingConfiguration="basicHttpBinding" 
      name="basicHttpBinding"
      bindingName=""
      contract="Service.MyService" />
    <host>
      <baseAddresses>
        <add baseAddress="http://localhost:50282/Service.svc" />
      </baseAddresses>
    </host>
  </service>
</services>
<bindings>
  <basicHttpBinding>
    <binding name="basicHttpBinding" allowCookies="true">
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="Basic" proxyCredentialType="None" />
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </basicHttpBinding>
  <wsHttpBinding>
    <binding name="wsHttpBinding" allowCookies="true">
      <security mode="TransportWithMessageCredential">
        <transport clientCredentialType="Basic" />
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<behaviors>
  <serviceBehaviors>
    <behavior name="basicHttpBehavior">
      <serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
      <serviceDebug includeExceptionDetailInFaults="true"/>
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="e3kConnector.App_Data.Security.CustomUserNameValidator,e3kConnector"/>
        <serviceCertificate findValue="tempCert" storeLocation="LocalMachine" storeName="My" x509FindType="FindBySubjectName"/>
      </serviceCredentials>
      <serviceAuthorization principalPermissionMode="Custom">
        <authorizationPolicies>
          <add policyType="e3kConnector.App_Data.Security.AuthorizationPolicy, e3kConnector"/>
        </authorizationPolicies>
      </serviceAuthorization>
    </behavior>
  </serviceBehaviors>
</behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="false"/>
</system.serviceModel>
<system.webServer>
  <modules runAllManagedModulesForAllRequests="true"/>
  <!--
    To browse web app root directory during debugging, set the value below to true.
    Set to false before deployment to avoid disclosing web app folder information.
    -->
  <directoryBrowse enabled="true"/>
</system.webServer>

作为测试,我添加了这个tempConverter,但这有效。(是的,我知道这是一个 asmx 文件。)我也知道 svc 和 asmx 之间的区别,但这就是我感到困惑的原因。两者都支持 SOAP,所以我仍然不明白为什么它不起作用。也许这很简单?

如果您需要更多详细信息,请告诉我。

4

1 回答 1

1

发生这种情况是因为 Windows 应用商店客户端应用程序仅支持WCF 的一小部分

在您的服务上尝试这个精简配置(删除绑定 wsHttp、行为和绑定配置):

<system.serviceModel>
  ....
  <services>
    <service name="e3kConnector.E3KConnectorService">
      <endpoint
        address="mex"
        binding="mexHttpBinding"
        contract="IMetadataExchange" />
      <endpoint
        address=""
        binding="basicHttpBinding"
        name="basicHttpBinding"
        contract="Service.MyService" />
      <host>
        <baseAddresses>
          <add baseAddress="http://localhost:50282/Service.svc" />
        </baseAddresses>
      </host>
    </service>
  </services>
  ....
</system.serviceModel>
于 2013-09-20T13:40:49.520 回答