404尝试访问WCF服务时

时间:2014-12-23 03:57:21

标签: wcf

我刚刚开始使用WCF,并且在使邮件加密工作时遇到了一些麻烦。我终于使用基于角色的身份验证与Asp.Net Identity 2.0一起工作,现在我正在尝试保护所有通过加密交换的数据。我使用SelfCert签署了自己的x.509证书。现在,当我尝试在合同上点击任何方法时,我得到了404.我认为问题可能出现在我的web.configs中。任何人都可以在这些web.config文件中指出任何明显的 noobie错误吗?

服务配置

 <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior name="authBehavior">
      <serviceCredentials>
        <serviceCertificate findValue="onpSquad"
                            storeLocation="LocalMachine"
                            storeName="My"
                             x509FindType="FindBySubjectName"/>
        <clientCertificate>
          <authentication certificateValidationMode="None" />
        </clientCertificate>
        <userNameAuthentication userNamePasswordValidationMode="Custom"  customUserNamePasswordValidatorType="WCFServiceWebRole1.Onp.Security.IdentityValidator,WCFServiceWebRole1" />
      </serviceCredentials>
      <serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="WCFServiceWebRole1.Onp.Security.RoleAuthorizationManager,WCFServiceWebRole1">

      </serviceAuthorization>

    </behavior>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<services>
  <service behaviorConfiguration="authBehavior" name="WCFServiceWebRole1.SupportTicketSubmission">
    <endpoint address="SupportTicketSubmission.svc"
              binding="wsHttpBinding"
              bindingConfiguration="MessageAndUserName"
              name="SecuredByTransportEndpoint"
              contract="WCFServiceWebRole1.Onp.IServiceSquadContract" />
  </service>
</services>
<bindings>
  <wsHttpBinding>
    <binding name="MessageAndUserName">
      <security mode="Message">
        <message clientCredentialType="UserName" />
      </security>
    </binding>
  </wsHttpBinding>
</bindings>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

客户端

 <system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="BasicHttpBinding_IServiceSupportTicketSubmission" />
            <binding name="BasicHttpBinding_IServiceLoggingContract" />
        </basicHttpBinding>
        <wsHttpBinding>
            <binding name="WSHttpBinding_IService1" />
          <binding name="WSHttpBinding_IServiceSquadContract">
            <security mode="Message">
              <message clientCredentialType="UserName" />
            </security>
          </binding>
        </wsHttpBinding>
    </bindings>
    <client>
        <endpoint address="http://localhost:64054/Service1.svc" binding="wsHttpBinding"
            bindingConfiguration="WSHttpBinding_IService1" contract="ServiceReference1.IService1"
            name="WSHttpBinding_IService1">
            <identity>
                <userPrincipalName value="MARIASCOMPUTER\chuyita" />
            </identity>
        </endpoint>
        <endpoint address="http://localhost:10234/SupportTicketSubmission.svc"
            binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServiceSupportTicketSubmission"
            contract="OnpService.IServiceSupportTicketSubmission" name="BasicHttpBinding_IServiceSupportTicketSubmission" />
      <endpoint address="http://localhost:10234/SupportTicketSubmission.svc"
           binding="wsHttpBinding"
           bindingConfiguration="WSHttpBinding_IServiceSquadContract"
           contract="OnpService.IServiceSquadContract"
           name="SecuredByTransportEndpoint">
        <identity>
          <dns value ="onpSquad" />
        </identity>
      </endpoint>

    </client>
</system.serviceModel>

旧配置文件

从下面可以看出,从未定义任何明确的端点。这是我第一次真正定义它们,以便我可以使用ASP.Net的Identity 2.0登录并设置加密。

 <system.serviceModel>
<behaviors>
  <serviceBehaviors>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />

到目前为止更新

我有一本WCF书并阅读了第一章。我的绑定工作正常,我能够访问我的ISquadContract的方法,但现在我遇到的问题是Identity 2.0没有从请求中获取提供的用户名。这是另一个问题的主题。这是我的新配置的样子

 <system.serviceModel>
<protocolMapping>
  <add scheme="http" binding="wsHttpBinding"/>
</protocolMapping>
<services>
  <service name="WCFServiceWebRole1.SupportTicketSubmission"
            behaviorConfiguration="authBehavior"
            >
    <endpoint address="SupportTicketSubmission.svc"
               binding="wsHttpBinding"
               contract="WCFServiceWebRole1.Onp.IServiceSquadContract"
               bindingConfiguration="squadBindingConfiguration">

    </endpoint>
  <endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex"></endpoint>
  </service>
</services>
<behaviors>
  <serviceBehaviors>
    <behavior name="authBehavior">
      <serviceMetadata httpGetEnabled="true"/>
      <serviceCredentials>
        <userNameAuthentication userNamePasswordValidationMode="Custom"  customUserNamePasswordValidatorType="WCFServiceWebRole1.Onp.Security.IdentityValidator,WCFServiceWebRole1" />
      </serviceCredentials>
      <serviceAuthorization principalPermissionMode="Custom" serviceAuthorizationManagerType="WCFServiceWebRole1.Onp.Security.RoleAuthorizationManager,WCFServiceWebRole1">
      </serviceAuthorization>

    </behavior>
    <behavior>
      <!-- To avoid disclosing metadata information, set the value below to false before deployment -->
      <serviceMetadata httpGetEnabled="true"/>
      <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
      <serviceDebug includeExceptionDetailInFaults="true"/>
    </behavior>
  </serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
  <wsHttpBinding>
    <binding name="squadBindingConfiguration">
      <security mode="None">
        <message clientCredentialType="UserName"/>
      </security>
    </binding>
  </wsHttpBinding>
</bindings>

1 个答案:

答案 0 :(得分:0)

您的客户端配置文件似乎定义了配置,以允许它连接到三个不同的服务端点,一个在地址可用:

http://localhost:64054/Service1.svc

期待找到一个公开合同的服务:

ServiceReference1.IService1

以及其他两个地址:

http://localhost:10234/SupportTicketSubmission.svc

但是,其中一个人希望调用名为的服务合同:

OnpService.IServiceSupportTicketSubmission 

另一个希望调用名为的服务合同:

OnpService.IServiceSquadContract

另一方面,您的服务配置文件定义了基本服务地址可用的服务端点:

SupportTicketSubmission.svc

并揭露合同:

WCFServiceWebRole1.Onp.IServiceSquadContract

这就像我认为在两个应该一起工作的WCF配置文件中见过的图片一样混乱。这里有很多问题。如果您希望我帮助您解决此问题,请在下面写下评论。

相关问题