Windows 8 Store App和WCF服务

时间:2013-09-20 08:40:47

标签: c# wcf web-services visual-studio-2012 windows-store-apps

如果我尝试在我的空白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,所以我仍然不明白为什么它不起作用。也许这很简单?

如果您需要更多详情,请告诉我们。

1 个答案:

答案 0 :(得分:1)

这是因为Windows应用商店客户端应用仅支持small subset of 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>