2012-07-25 132 views
1

獲取試圖執行CRM Web服務時以下錯誤\錯誤請求415

代碼

  CrmAuthenticationToken token = new CrmAuthenticationToken(); 
      token.AuthenticationType = 0; //Use AD authentication 
      token.OrganizationName = "Organization"; 
      CrmService service= new CrmService(); 
      service.CrmAuthenticationTokenValue = token; 
      service.Credentials = System.Net.CredentialCache.DefaultCredentials; 
      service.PreAuthenticate=true; 
      WhoAmIRequest whoami = new WhoAmIRequest(); 
      WhoAmIResponse whoResp = ((WhoAmIResponse)(service.Execute(whoami))); 

配置設置:

<add key="CrmSdk.CrmServiceWsdl" value="http://server/organization/XRMServices/2011/Organization.svc/web"/> 

錯誤:

System.Net.WebException:請求失敗,HTTP狀態415:無法處理消息,因爲內容類型爲'text/xml; charset = utf-8'不是預期的類型'application/soap + xml; charset = utf-8'..

如果我改變我的配置設置,如下所示,我得到「壞請求」。

配置設置:

<add key="CrmSdk.CrmServiceWsdl" value="http://server/organization/XRMServices/2011/Organization.svc/web"/> 

錯誤:

The message with Action 'http://schemas.microsoft.com/crm/2007/WebServices/Execute' cannot be processed at the receiver, due to a ContractFilter mismatch at the EndpointDispatcher. This may be because of either a contract mismatch (mismatched Actions between sender and receiver) or a binding/security mismatch between the sender and the receiver. Check that sender and receiver have the same contract and the same binding (including security requirements, e.g. Message, Transport, None).

回答

2

你有這樣的設置對於2007端點,所以你需要你的價值從改變:

value="http://server/organization/XRMServices/2011/Organization.svc/web" 

value="http://server/org/MSCRMServices/2007/CrmService.asmx" 

如果您嘗試使用2011,則需要使用IOrganizationService。有在SDK http://www.microsoft.com/en-us/download/details.aspx?id=24004

這裏一些非常好的例子是另外一個例子,以及http://nishantrana.wordpress.com/2010/11/03/sample-code-for-using-iorganizationservice-in-crm-2011/