Using a web service with Microsoft Dynamics CRM 20

2019-05-27 22:12发布

问题:

I'm having an issue connecting to a web service for use in a MS Dynamics 2013 plugin (running in sandbox mode because its on the MS hosted online version, not the in house version)

The issue I'm facing is that i cannot seem to connect to a web service i need to use to achieve what I'm attempting to do.

I initially had the web service binding in the app.config, but i quickly learnt that the app.config is irrelevant in this case (?), so i moved on to creating the binding in the code. this is the code i came up with:

BasicHttpBinding myBinding = new BasicHttpBinding();
myBinding.Name = "BasicHttpBinding_IClientSearch";
myBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;
myBinding.Security.Transport.ProxyCredentialType = HttpProxyCredentialType.None;
myBinding.Security.Message.ClientCredentialType = BasicHttpMessageCredentialType.UserName;
myBinding.MaxBufferSize = 524288;
myBinding.MaxBufferPoolSize = 524288;
myBinding.MaxReceivedMessageSize = 524288;
myBinding.ReaderQuotas.MaxDepth = 32;
myBinding.ReaderQuotas.MaxArrayLength = 524288;
myBinding.ReaderQuotas.MaxStringContentLength = 524288;
myBinding.Security.Mode = BasicHttpSecurityMode.TransportWithMessageCredential;
EndpointAddress endPointAddress = new EndpointAddress(EndPointURL);
ClientSearchService.ClientSearchClient myClient = new ClientSearchService.ClientSearchClient(myBinding, endPointAddress);
myClient.Open();

When I deploy this to the dynamics server and trigger the code it throws this error:

The Binding with name BasicHttpBinding_IClientSearch failed validation 
because it contains a BindingElement with type System.ServiceModel.Channels.TransportSecurityBindingElement 
which is not supported in partial trust. 
Consider using BasicHttpBinding or WSHttpBinding, or hosting your application in a full-trust environment.

Obviously because its on Microsofts own hosting platform i am incapable of running it in a full trust enviroment, I do require it being BasicHttpSecurityMode.TransportWithMessageCredential because i need to supply a username/password to access the service.

Is there a workaround for this problem, or am i incapable of completing this task using a plugin?