I’m getting the following error when calling a webservice from a function.
I have referenced all the required assemblies in sql server with “unsafe” permission set and have registered the project assembly with “external access” and the serializer assembly with “safe” permission sets. I have also looked into the code and I don’t see anything like message popup etc…that would be irrelevant in sql server’s context. I have created another console app that uses the same service and it can access the service just fine from the same server. What else could be causing this issue? Any help is appreciated.
Error: System.Security.HostProtectionException: Attempted to perform an operation that was forbidden by the CLR host. at System.ServiceModel.Description.TypeLoader.LoadContractDescriptionHelper(Type contractType, Type serviceType, Object serviceImplementation) at System.ServiceModel.ChannelFactory1.CreateDescription() at System.ServiceModel.ChannelFactory.InitializeEndpoint(Binding binding, EndpointAddress address) at System.ServiceModel.ChannelFactory1..ctor(Binding binding, EndpointAddress remoteAddress) at System.ServiceModel.ClientBase`1..ctor(Binding binding, EndpointAddress remoteAddress) at MWMInterfaceBeanServiceClient.MWMInterfaceBeanServiceClient..ctor(Binding binding, EndpointAddress remoteAddress) at MWMInterfaceBeanServiceClient.MWMServiceClient.GetClient() at MWMInterfaceBeanServiceClient.MWMServiceClient.UpdateMobileCrew(Boolean active, Boolean available, Boolean availForOp, String contract, String code, String name, Int32 number, String crewCenter, String crewGroup, String crewId, Int32 crewSize, String crewSupervisor, String crewType, Boolean mdtCrew, SqlXml members, String district, String division, String serviceArea, String mobileNum, String pagerNum, Boolean tempFlag, SqlXml vehicles) The protected resources (only available with full trust) were: All The demanded resources were: Synchronization, ExternalThreading
so, I marked the assemblies as UNSAFE and that made this error go away but gave me another error that said it wasn’t able to serialize one of the proxies generated by svcutil to make the request. I already had the serializer assembly generated using sgen in a post build task and registered as UNSAFE and it seems that didn’t work. Maybe this only works for simple methods with native types? Therefore, I resorted to a different method mentioned in the following link.
http://www.vishalseth.com/post/2009/12/22/Call-a-webservice-from-TSQL-(Stored-Procedure)-using-MSXML.aspx