2011-09-23 1 views
2

テストコンソールアプリケーションからCRM 2011 Organization.svcへのサービス参照を作成しました。 すべては、app.configで生成されたバインディングを使用して完全に動作します。(Microsoft hereが提供するサービスの例)app.configを使用せずにWCFバインディングで正しいコンテンツタイプを設定するにはどうすればよいですか?

これを「実際の」アプリケーションに移動し、GACに展開するDLLでホストする必要があります。アプリの規約に従って、というバインディングはコードで生成する必要があります。

私たちは、当社の他のWCFサービスのために使用バインディングを使用しようとしてスタートしました:(OrganizationRequestでExecuteメソッドを使用して)

BasicHttpBinding binding = new BasicHttpBinding(); 
binding.SendTimeout = TimeSpan.FromMinutes(1); 
binding.OpenTimeout = TimeSpan.FromMinutes(1); 
binding.CloseTimeout = TimeSpan.FromMinutes(1); 
binding.ReceiveTimeout = TimeSpan.FromMinutes(10); 
binding.AllowCookies = true; 
binding.BypassProxyOnLocal = false; 
binding.HostNameComparisonMode = HostNameComparisonMode.StrongWildcard; 
binding.MessageEncoding = WSMessageEncoding.Text; 
binding.TextEncoding = System.Text.Encoding.UTF8; 
binding.TransferMode = TransferMode.Buffered; 
binding.UseDefaultWebProxy = true; 
binding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly; 
binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows; 

残念ながら、WCFサービスが呼び出された時点では、このエラー発生:

System.ServiceModel.ProtocolException:コンテンツタイプtext/xmlで、 charset = utf-8はサービスhttp://server:5555/xrmservices/2011/organization.svcでサポートされていませんでした。クライアントとサービスのバインドが一致していない可能性があります。

は、私は特定の問題が結合であるものわからないんだけど、コードに変換で私の試みは、これまでのところ、同じエラーで失敗しています。ここで働いて結合のapp.configで定義されています:誰もがコード内で正しい結合を設定し、および/またはXMLからの結合を読み取る方法

<bindings> 
    <customBinding> 
     <binding name="CustomBinding_IOrganizationService"> 
      <security defaultAlgorithmSuite="Default" authenticationMode="SspiNegotiated" 
       requireDerivedKeys="true" securityHeaderLayout="Strict" includeTimestamp="true" 
       keyEntropyMode="CombinedEntropy" messageProtectionOrder="SignBeforeEncryptAndEncryptSignature" 
       messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10" 
       requireSecurityContextCancellation="true" requireSignatureConfirmation="false"> 
       <localClientSettings cacheCookies="true" detectReplays="true" 
        replayCacheSize="900000" maxClockSkew="00:05:00" maxCookieCachingTime="Infinite" 
        replayWindow="00:05:00" sessionKeyRenewalInterval="10:00:00" 
        sessionKeyRolloverInterval="00:05:00" reconnectTransportOnFailure="true" 
        timestampValidityDuration="00:05:00" cookieRenewalThresholdPercentage="60" /> 
       <localServiceSettings detectReplays="true" issuedCookieLifetime="10:00:00" 
        maxStatefulNegotiations="128" replayCacheSize="900000" maxClockSkew="00:05:00" 
        negotiationTimeout="00:01:00" replayWindow="00:05:00" inactivityTimeout="00:02:00" 
        sessionKeyRenewalInterval="15:00:00" sessionKeyRolloverInterval="00:05:00" 
        reconnectTransportOnFailure="true" maxPendingSessions="128" 
        maxCachedCookies="1000" timestampValidityDuration="00:05:00" /> 
       <secureConversationBootstrap /> 
      </security> 
      <textMessageEncoding maxReadPoolSize="64" maxWritePoolSize="16" 
       messageVersion="Default" writeEncoding="utf-8"> 
       <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" 
        maxBytesPerRead="4096" maxNameTableCharCount="16384" /> 
      </textMessageEncoding> 
      <httpTransport manualAddressing="false" maxBufferPoolSize="524288" 
       maxReceivedMessageSize="65536" allowCookies="false" authenticationScheme="Anonymous" 
       bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" 
       keepAliveEnabled="true" maxBufferSize="65536" proxyAuthenticationScheme="Anonymous" 
       realm="" transferMode="Buffered" unsafeConnectionNtlmAuthentication="false" 
       useDefaultWebProxy="true" /> 
     </binding> 
    </customBinding> 
</bindings> 

を知っていますか?

答えて

1

カスタムチャネルファクトリを作成することは、これを解決するための重要な部分です。

記事Get your WCF client configuration from anywhereは、カスタムサービスクライアントを使用して任意の場所から.configファイルを読むのに非常に役立ちます。

すべての値をapp.config形式と非常によく似た方法で設定する方法については、Calling WCF Service using Client Channel Factory(カスタムバインディングの作成方法)を参照してください。私は、すべてのセキュリティプロパティがこのように設定されているわけではないことを発見しました(または少なくとも私はそれらを見つけることができませんでした)。

2

私はちょうど解決するために同じタスクを持っていました。これは私のために働いた(httpのために)。

var security = SecurityBindingElement.CreateSspiNegotiationBindingElement(); 
security.DefaultAlgorithmSuite = SecurityAlgorithmSuite.Default; 
security.SecurityHeaderLayout = SecurityHeaderLayout.Strict; 
security.IncludeTimestamp = true; 
security.KeyEntropyMode = SecurityKeyEntropyMode.CombinedEntropy; 
security.MessageProtectionOrder = MessageProtectionOrder.SignBeforeEncryptAndEncryptSignature; 
security.MessageSecurityVersion = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10; 

security.LocalClientSettings.CacheCookies = true; 
security.LocalClientSettings.DetectReplays = true; 
security.LocalClientSettings.ReplayCacheSize = 900000; 
security.LocalClientSettings.MaxClockSkew = new TimeSpan(0, 5, 0); 
security.LocalClientSettings.MaxCookieCachingTime = new TimeSpan(23, 0, 0, 0); 
security.LocalClientSettings.ReplayWindow = new TimeSpan(0, 5, 0); 
security.LocalClientSettings.SessionKeyRenewalInterval = new TimeSpan(15, 0, 0); 
security.LocalClientSettings.SessionKeyRolloverInterval = new TimeSpan(0, 5, 0); 
security.LocalClientSettings.ReconnectTransportOnFailure = true; 
security.LocalClientSettings.TimestampValidityDuration = new TimeSpan(0, 5, 0); 
security.LocalClientSettings.CookieRenewalThresholdPercentage = 60; 

security.LocalServiceSettings.DetectReplays = true; 
security.LocalServiceSettings.IssuedCookieLifetime = new TimeSpan(10, 0, 0); 
security.LocalServiceSettings.MaxStatefulNegotiations = 128; 
security.LocalServiceSettings.ReplayCacheSize = 900000; 
security.LocalServiceSettings.MaxClockSkew = new TimeSpan(0, 5, 0); 
security.LocalServiceSettings.NegotiationTimeout = new TimeSpan(0, 1, 0); 
security.LocalServiceSettings.ReplayWindow = new TimeSpan(0, 5, 0); 
security.LocalServiceSettings.InactivityTimeout = new TimeSpan(0, 2, 0); 
security.LocalServiceSettings.SessionKeyRenewalInterval = new TimeSpan(15, 0, 0); 
security.LocalServiceSettings.SessionKeyRolloverInterval = new TimeSpan(0, 5, 0); 
security.LocalServiceSettings.ReconnectTransportOnFailure = true; 
security.LocalServiceSettings.MaxPendingSessions = 128; 
security.LocalServiceSettings.MaxCachedCookies = 1000; 
security.LocalServiceSettings.TimestampValidityDuration = new TimeSpan(0, 5, 0); 

var textEncoding = new TextMessageEncodingBindingElement 
{ 
    MaxReadPoolSize = 64, 
    MaxWritePoolSize = 16, 
    MessageVersion = MessageVersion.Default, 
    WriteEncoding = System.Text.Encoding.UTF8, 
    ReaderQuotas = new XmlDictionaryReaderQuotas 
    { 
     MaxDepth = 32, 
     MaxArrayLength = 16384, 
     MaxBytesPerRead = 4096, 
     MaxNameTableCharCount = 16384, 
     MaxStringContentLength = 8192 
    } 
}; 

var httpTransport = new HttpTransportBindingElement 
{ 
    ManualAddressing = false, 
    MaxBufferSize = 65536, 
    MaxReceivedMessageSize = 65536, 
    AllowCookies = false, 
    AuthenticationScheme = AuthenticationSchemes.Anonymous, 
    BypassProxyOnLocal = false, 
    DecompressionEnabled = true, 
    HostNameComparisonMode = HostNameComparisonMode.StrongWildcard, 
    KeepAliveEnabled = true, 
    MaxBufferPoolSize = 524288, 
    ProxyAuthenticationScheme = AuthenticationSchemes.Anonymous, 
    TransferMode = TransferMode.Buffered, 
    UnsafeConnectionNtlmAuthentication = false, 
    UseDefaultWebProxy = true, 
}; 

var binding = new CustomBinding(new List<BindingElement> { security, textEncoding, httpTransport }); 
var endpoint = new EndpointAddress(_serviceUri); 

var service = new OrganizationServiceClient(binding, endpoint); 
関連する問題