1

WCF サービスを WebSite App_Code フォルダーからプロジェクト ライブラリに移行したいと考えています。私の知る限り、WCF ライブラリはサービス モデルに関する Web 構成を読み取ることができるため、私が行った唯一のアクションは次のとおりです。1 - 新しいプロジェクト ライブラリを作成し、wcf に関するすべてのコードを app_code からそれに配置します。2 - 完全修飾名 (名前空間 + クラス名) を持つサービス クラスを指すように Web 構成を変更します。 3 - 完全修飾名を持つサービス クラス インスタンスを指すように svc ファイルを変更します。

ただし、私のサービスはもう実行されていません。カスタムバリデーターで ws-httpbinding を使用していますが、私のサービスは基本的な http バインディングを想定しているようです。私が苦労しているエラーは次のように表示されます: コントラクト操作 ('IMyService',' http://tempuri.org/ ') で要求されるなど、メッセージのリクエストを保護する必要があります。保護は、('BasicHttpBinding',' http://tempuri.org/ ') バインディングによって実装する必要があります。

@@編集:

私の Web.Config:

  <system.serviceModel>
    <behaviors>
      <serviceBehaviors>
        <behavior name="MyBehavior">
          <serviceMetadata httpGetEnabled="true" />
          <serviceDebug includeExceptionDetailInFaults="true" />
          <serviceCredentials>
            <userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MyWcfNamespaceOfMyDLL.MyCustomValidator" />
            <serviceCertificate findValue="localhost" x509FindType="FindBySubjectName" storeLocation="LocalMachine" storeName="My" />
          </serviceCredentials>
        </behavior>
      </serviceBehaviors>
    </behaviors>
    <bindings>
      <wsHttpBinding>
        <binding name="MyBinding" maxBufferPoolSize="1000000000" maxReceivedMessageSize="1000000000" messageEncoding="Mtom">
          <security mode="Message">
            <message clientCredentialType="UserName" />
          </security>
        </binding>
      </wsHttpBinding>
    </bindings>
    <services>
      <service behaviorConfiguration="MyBehavior" name="MyServiceName">
        <endpoint address="" binding="wsHttpBinding" contract="MyWcfNamespaceOfMyDLL.IMyServiceName" bindingConfiguration="MyBinding">
          <identity>
            <dns value="localhost" />
          </identity>
        </endpoint>
        <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
      </service>
    </services>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
</configuration>

これは、Web サイトのルート内にある私の svc ファイルです。

<%@ ServiceHost Language="C#" Debug="true" Service="MyWcfNamespaceOfMyDLL.MyServiceName" %>

最後に、dll 内のサービス コントラクトは次のように表示されます。

[ServiceContract]
public interface IMyService
{
    [OperationContract(ProtectionLevel=System.Net.Security.ProtectionLevel.EncryptAndSign)]
    string DoSomething();
}

public class MyServiceName : IMyService
{
   public string DoSomething();
}

public class MyValidator : UserNamePasswordValidator
    {
// simple validation
}

何か案が?

4

2 に答える 2

0

問題はクライアントではなく、サービスに起因していると確信していますか?

このサービスの呼び方を教えてください。

メッセージのリクエストは、コントラクト操作 ('IMyService'、' http://tempuri.org/ ')で要求されるなど、保護する必要があります。保護は、('BasicHttpBinding',' http://tempuri.org/ ') バインディングによって実装する必要があります。

ここで述べたように、

バインディングがセキュリティ (BasicHttpBinding など) をサポートしていない場合、有効な System.Net.Security.ProtectionLevel はコントラクト全体で ProtectionLevel.None になります。その結果、コントラクトで ProtectionLevel.None が指定されている場合でも、エンドポイント バインディングに応じて、クライアントは異なるメッセージまたはトランスポート レベルのセキュリティ保護を要求できます。

このエラー メッセージは、ProtectionLevel のない basicHttpBinding でサービスを呼び出していることを示しています。

また、Web.config のコントラクトはIMyServiceName、コード 'IMyService' またはエラー メッセージ内のものと同じではありません。

于 2013-05-30T18:35:24.407 に答える