SQL CLR Stored Procedure calling Web Service receives System.Net.WebException: The request failed with HTTP status 415: Unsupported Media Type

StackOverflow https://stackoverflow.com/questions/23389050

Вопрос

I have created a SQL CLR Project in Visual Studio 2012 (Target Framework: 3.5) that will call a Web Service (WCF). Initially, I had created a Web reference to the web service in the project, but I kept getting 'Could not load dynamically generated assembly' when executing the stored procedure created. After a lot of googling, I used wsdl utility to create a code from the web service's WSDL and add it to the project.

I had turned on the 'Generate serialization assembly' in the project's properties page to generate the Serialized DLL since sgen utility did not work for me. On the database (SQL Server 2008) side, I have enabled CLR and set the database's trustworthy to on.

Then, I registered the CLR assembly and the Serialized DLL in the database and created the procedure like so:

CREATE ASSEMBLY [Database] FROM 'C:\MyProject\bin\Debug\Database.dll' WITH PERMISSION_SET = UNSAFE;
CREATE ASSEMBLY [Database.XmlSerializers] FROM 'C:\MyProject\bin\Debug\Database.XmlSerializers.dll' WITH PERMISSION_SET = UNSAFE;  

CREATE PROCEDURE [dbo].[XSP_AlertReachedMilestone] @milestoneID INT 
 WITH EXECUTE AS CALLER
AS EXTERNAL NAME [Database].[StoredProcedures].[XSP_AlertReachedMilestone] 

But when I executed the Stored procedure, I received 'Unsupported Media Type' exception. I googled the error one of the suggestion recommended checking the SOAP versions of the client(Database) and web service. I have verified that the web service uses SOAP 1.2 but I don't know how to check what SOAP version the SQL Server is using.

Another suggested to check the content/mime type of the client (database), but again I don't know how to check this.

Any ideas how can I fix this error?

Это было полезно?

Решение

I have solved this issue. I found out that the problem was the web reference which do not work with WCF and CLR. After finding this out I generated the proxy class for the web service using wsdl.exe utility but it doesn't create the code correctly. Using svcutil.exe utility to generate the proxy class did the trick for me. I then add the proxy class generated to my project and compile the assembly.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top