2012-07-25 102 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/