2016-07-22 13 views
1

CRMオンラインをクエリするときに、basicHttpBindingではなく、wsHttpBinding経由でリクエストを送信するようにASP.NET Webフォームを設定するにはどうすればよいですか?CRMオンラインに問い合わせるときにwsHttpBindingを使用するようにASP.NET Webページを設定するにはどうすればよいですか?

これは、IIS 8.5でローカルにホストされているかなり基本的なASPXページです。
このページは、CRM Onlineに接続してデータを取得するためのものです。
編集:このアプリはAzure ADを介して認証されているため、クライアントIDとキーが使用されます。これがやむを得ない場合を除いて、接続文字列とドメイン資格情報の使用を躊躇したい。

は、私が正しいCRMへの認証を持っていると思いますが、私は、クエリを実行すると、私は下のエラーが表示されます。私は指定していないので、これはあると思い

System.Net.WebException: The remote server returned an error: (415) Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'..

web.configに結合そう私のページはbasicHttpBindingを介してすべてを送信しており、CRMオンラインインターフェイスはwsHttpBindingが必要です。

this MSDN article(およびその変形例)の下の例を使用してみましたが、違いはありません。

違いがある場合に備えて、CRMに接続するためのコードは次のとおりです。明らかに、実際の設定の詳細がわかりません。

[WebException: The remote server returned an error: (415) Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'..] System.Net.HttpWebRequest.GetResponse() +1740 System.ServiceModel.Channels.HttpChannelRequest.WaitForReply(TimeSpan timeout) +75

[ProtocolException: Content Type text/xml; charset=utf-8 was not supported by service https://dev.crm4.dynamics.com/XRMServices/2011/Discovery.svc . The client and service bindings may be mismatched.] System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +14350190 System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +388 Microsoft.Xrm.Sdk.IOrganizationService.RetrieveMultiple(QueryBase query) +0 Microsoft.Xrm.Sdk.WebServiceClient.WebProxyClient 1.ExecuteAction(Func 1 action) +51 Quote_Robot_Demo.d__4.MoveNext() +887 System.Runtime.CompilerServices.<>c.b__6_0(Object state) +56 System.Web.Util.SynchronizationHelper.SafeWrapCallback(Action action) +110 System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +13847892 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +61 System.Web.Util.WithinCancellableCallbackTaskAwaiter.GetResult() +32 System.Web.UI.d__523.MoveNext() +7970

編集:ここでは

// CONFIGURE OAUTH 
var tenantName = "mycompany.onmicrosoft.com"; 
var authString = string.Format(@"https://login.microsoftonline.com/{0}",tenantName); 
var authContext = new AuthenticationContext(authString, false); 
var clientId = "123ab123-123a-1a23-abcd-1a2345612345"; 
var key = "nStgfrdk0oyaC1P5+/FQ4wGn4fRgUTr8HTKejytf0bv="; 
var clientCred = new ClientCredential(clientId, key); 
var resource = "https://myinstance.crm4.dynamics.com"; 

// ACQUIRE THE AUTH TOKEN 
var authResult = await authContext.AcquireTokenAsync(resource, clientCred); 

// CREATE THE CONNECTION TO CRM 
var orgService = new OrganizationWebProxyClient(
    new Uri("https://dev.crm4.dynamics.com/XRMServices/2011/Discovery.svc"), true) 
    { 
     HeaderToken = authResult.AccessToken, 
     SdkClientVersion = "8.1.0" 
    }; 

// RUNNING THIS QUERY CAUSES THE ERROR 
var contacts = orgService.RetrieveMultiple(new QueryExpression 
{ 
    EntityName = "contact", 
    ColumnSet = new ColumnSet("firstname", "lastname") 
}) 
.Entities 
.Select(item => item.ToEntity<Contact>()); 

は、使用のだ場合のスタックトレースですIものの

<system.serviceModel> 
<bindings> 
    <customBinding> 
    <binding name="CustomBinding_IDiscoveryService"> 
     <textMessageEncoding /> 
     <httpsTransport /> 
    </binding> 
    </customBinding> 
</bindings> 
<client> 
    <endpoint address="https://dev.crm4.dynamics.com/XRMServices/2011/Discovery.svc" 
    binding="customBinding" bindingConfiguration="CustomBinding_IDiscoveryService" 
    contract="CRMService.IDiscoveryService" name="CustomBinding_IDiscoveryService" /> 
</client> 
</system.serviceModel> 
+0

なぜ車輪を改造するのですか? https://msdn.microsoft.com/en-us/library/gg695810(v=crm.7).aspx – dynamicallyCRM

+0

このアプリケーションは、Azure ADを介して認証されるため、 SDKの例では接続文字列を使用していますが、Windowsの資格情報が必要なので、やりたくありません。私はこれについてより具体的に私の質問を編集します。 – Equalsk

+0

CRM SDKはオンプレミスインストールだけでなく、CRMオンラインバージョンもサポートしているため、アプリケーションのホスティング方法にかかわらず、SDKの使用方法に関係なく、SDKインスタンスを使用してCRMインスタンスに接続できます。また、バックグラウンドのSDKは、達成しようとしているものを正確に処理し、すべての通信チャネルを処理します。 – dynamicallyCRM

答えて

0

:私は私のweb.configファイルでこれを持ってサービス参照を追加したら、今私はバインディングを変更する方法を発見したいくつかの他の問題があります。
あなたは、私が行ったように、プロジェクトへのサービスの参照として、組織のサービスを追加し、次のように結合割り当てることができます。

orgService.Endpoint.Binding = new CustomBinding("CustomBinding_IOrganizationService"); 

カスタムバインディングに渡された文字列が設定から取られた名前だけです。

<system.serviceModel> 
    <bindings> 
    <customBinding> 
     <binding name="CustomBinding_IOrganizationService"> 
     .... 

編集:後で、バインディングを変更する必要はないことが判明しました。このエラーは、無効なセキュリティトークンによって引き起こされたようです。私はgrant_typepasswordにするためにセキュリティトークンを生成する方法を変更し、エラーはそれ自身で消え去った。

関連する問題