404尝试访问WCF服务时

时间:2021-07-17 20:28:51

I am just getting started with WCF and am having a bit of trouble getting my message encryption to work. I finally got Role based authentication working with Asp.Net Identity 2.0 and am now trying to secure all data exchanged with encryption. I have signed my own x.509 certificate using SelfCert. Now when I try to hit any method on my contract I get a 404. I think the problem might be somewhere in my web.configs. Can anyone point out any obvious noobie mistakes in these web.config files?

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

Service Config

 <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" />

The client

 <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>

Old config file

As you can see from below, there were never any explicit endpoints defined. This is the first time I actually have to define them so that I can use ASP.Net's Identity 2.0 for logging in and also setting up encryption.

从下面可以看出,从未定义任何明确的端点。这是我第一次真正定义它们,以便我可以使用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" />

Update thus far

I got a WCF book and read the first chapter. I've got my binding working correctly and I am able to access the methods of my ISquadContract but now am having issues with Identity 2.0 not grabbing the provided username from the request. That's a topic for another question. Here is what my new config looks like

我得到了一本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 个解决方案

#1


0  

Your client configuration file appears to define config to allow it to connect to three distinct service endpoints, one available at the address:

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

http://localhost:64054/Service1.svc

which is expecting to find there a service which exposes a contract called:

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

ServiceReference1.IService1

and the other two available at the address:

以及地址提供的其他两个:

http://localhost:10234/SupportTicketSubmission.svc

however, one of these is expecting to call the service contract called:

但是,其中一个人希望称之为服务合同:

OnpService.IServiceSupportTicketSubmission 

and the other one is expecting to call the service contract called:

而另一个人则希望将服务合同称为:

OnpService.IServiceSquadContract

Your service configuration file, on the other hand, defines a service endpoint available at the base service address of:

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

SupportTicketSubmission.svc

and exposing the contract:

并揭露合同:

WCFServiceWebRole1.Onp.IServiceSquadContract

This is about as confused a picture I think I have ever seen in two WCF config files which are supposed to work together. There are multiple problems here. If you want me to help you detangle this, write me a comment below.

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

#1


0  

Your client configuration file appears to define config to allow it to connect to three distinct service endpoints, one available at the address:

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

http://localhost:64054/Service1.svc

which is expecting to find there a service which exposes a contract called:

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

ServiceReference1.IService1

and the other two available at the address:

以及地址提供的其他两个:

http://localhost:10234/SupportTicketSubmission.svc

however, one of these is expecting to call the service contract called:

但是,其中一个人希望称之为服务合同:

OnpService.IServiceSupportTicketSubmission 

and the other one is expecting to call the service contract called:

而另一个人则希望将服务合同称为:

OnpService.IServiceSquadContract

Your service configuration file, on the other hand, defines a service endpoint available at the base service address of:

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

SupportTicketSubmission.svc

and exposing the contract:

并揭露合同:

WCFServiceWebRole1.Onp.IServiceSquadContract

This is about as confused a picture I think I have ever seen in two WCF config files which are supposed to work together. There are multiple problems here. If you want me to help you detangle this, write me a comment below.

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