0

単純なメッセージのユーザー名/パスワードアクセスができるように、WCFサービスを機能させようとしています。

現在の設定でサービスにアクセスしようとすると、次のように表示されます。

Metadata publishing for this service is currently disabled.

私のweb.config

  <system.serviceModel>
    <bindings>
      <wsHttpBinding>
        <binding name="Binding1">
          <!-- UsernameToken over Transport Security -->
          <security mode="Message" >
            <message clientCredentialType="UserName"/>
          </security>
        </binding>
      </wsHttpBinding>

    </bindings>
    <services>
      <service name="MyService" behaviorConfiguration="ServiceBehavior">
        <endpoint address="http://localhost/Service.svc" binding="wsHttpBinding" contract="IService" bindingConfiguration="Binding1">
          <identity>
            <dns value="localhost"/>
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior  name="ServiceBehavior">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above 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="false"/>
          <serviceCredentials>

            <!-- Use our own custom validation -->
            <userNameAuthentication userNamePasswordValidationMode="Custom"
                                                customUserNamePasswordValidatorType="WebApplication5.MyValidator, WebApplication5"/>
          </serviceCredentials>

        </behavior>
      </serviceBehaviors>
    </behaviors>
  </system.serviceModel>
</configuration>

私のMyService.svc:

namespace WebApplication5
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the    
class name "MyService" in code, svc and config file together.
    public class MyService : IMyService
    {
        public string DoWork()
        {
            return "You Got It";
        }
    }
}

私のMyValidator.cs:

namespace WebApplication5
{
    class MyValidator : UserNamePasswordValidator
    {
        public override void Validate(string userName, string password)
        {
            if ((userName == "shiv123") && (password == "pass123"))
            {
            }
            else
            {
                throw new FaultException("Invalid credentials");
            }
        }
    }
}
4

1 に答える 1

1

XMLのサービスには、名前空間が含まれている必要があります。

試してみてください:

<service name="WebApplication5.MyService" ...
于 2012-04-26T11:48:58.243 に答える