- Home /
using SOAP web service fails in windows build due to runtime code generation (2017.3, .net 4.6)
Hello!
I'm having a problem using a SOAP web service in a standalone windows build. We are using 2017.3 with experimental .net 4.6 scripting runtime enabled.
The web service client implementation was generated from the wsdl document using the wsdl.exe tool. Everything works fine when testing it in the editor, but in the standalone build it throws an exception when creating an instance of that client implementation class:
at Mono.CSharp.CSharpCodeCompiler.CompileFromFileBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] fileNames) [0x00162] in <3649452ae23840d49bd323a708498f78>:0
at Mono.CSharp.CSharpCodeCompiler.CompileFromSourceBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] sources) [0x00088] in <3649452ae23840d49bd323a708498f78>:0
at Mono.CSharp.CSharpCodeCompiler.CompileAssemblyFromSourceBatch (System.CodeDom.Compiler.CompilerParameters options, System.String[] sources) [0x0000f] in <3649452ae23840d49bd323a708498f78>:0
at System.CodeDom.Compiler.CodeDomProvider.CompileAssemblyFromSource (System.CodeDom.Compiler.CompilerParameters options, System.String[] sources) [0x00006] in <3649452ae23840d49bd323a708498f78>:0
at System.Xml.Serialization.Compiler.Compile (System.Reflection.Assembly parent, System.String ns, System.Xml.Serialization.XmlSerializerCompilerParameters xmlParameters, System.Security.Policy.Evidence evidence) [0x00144] in <03e950671d964403ab67ff751c460757>:0
at System.Xml.Serialization.TempAssembly.GenerateAssembly (System.Xml.Serialization.XmlMapping[] xmlMappings, System.Type[] types, System.String defaultNamespace, System.Security.Policy.Evidence evidence, System.Xml.Serialization.XmlSerializerCompilerParameters parameters, System.Reflection.Assembly assembly, System.Collections.Hashtable assemblies) [0x004c2] in <03e950671d964403ab67ff751c460757>:0
at System.Xml.Serialization.TempAssembly..ctor (System.Xml.Serialization.XmlMapping[] xmlMappings, System.Type[] types, System.String defaultNamespace, System.String location, System.Security.Policy.Evidence evidence) [0x0006a] in <03e950671d964403ab67ff751c460757>:0
at System.Xml.Serialization.XmlSerializer.GetSerializersFromCache (System.Xml.Serialization.XmlMapping[] mappings, System.Type type) [0x00111] in <03e950671d964403ab67ff751c460757>:0
at System.Xml.Serialization.XmlSerializer.FromMappings (System.Xml.Serialization.XmlMapping[] mappings, System.Type type) [0x000a2] in <03e950671d964403ab67ff751c460757>:0
at System.Web.Services.Protocols.SoapClientType..ctor (System.Type type) [0x000e1] in <3cfb32c731574db69b82bd4c837721a0>:0
at System.Web.Services.Protocols.SoapHttpClientProtocol..ctor () [0x0004f] in <3cfb32c731574db69b82bd4c837721a0>:0
at MantisConnect.MantisConnect..ctor () [0x00000] in <35039125407142ba85ccc2c953b98a76>:0
From what I've seen, it generates C# code for xml serialization and attempts to compile it. This works in the editor, but in a build it fails to find a mono compiler (obviously).
I then found out it's possible to use the sgen.exe tool to pre-generate an assembly containing the xml serializers, which is then supposed to be loaded and used instead of generating the code at runtime.
It seems that assembly is in fact loaded, but is still not used.
I spent days using ILSpy to understand what's going on, and have tried various things, but I just can't seem to get this to work.
So my question is: Does anyone successfully use a SOAP web service in a standalone windows build, and if so, how? Also, is the wsdl.exe + sgen.exe the correct way to generate the things I need, and am I just missing a detail?
Thanks in advance for any help/ideas/pointers in the right direction!
Answer by tom_sas · Jan 28, 2019 at 04:52 PM
Turns out wsdl.exe + sgen.exe does indeed work, BUT the sgen.exe tool provided as part of a unity installation (...\Editor\Data\MonoBleedingEdge\lib\mono\4.5\sgen.exe) does not generate everything that's needed. That's why the generated assembly is still not used in the end.
I've resolved the issue by using a sgen.exe tool provided as part of the microsoft SDKs, which does the job correctly. ILSpy showed that the generated assembly does indeed contain things that were missing before.
For anyone trying to find the sgen.exe tool, it was located under "C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6 Tools" on my machine. Various similar folders exist there which should have it.
Also, don't forget to add System.Web.Services.dll to your unity project. The one provided as part of unity works and can be found under "...\Editor\Data\MonoBleedingEdge\lib\mono\4.6-api"
Your answer
Follow this Question
Related Questions
Has anyone used the new .net 4.6 with ARCore and ARKit in production? 0 Answers
.NET framework 4.6 support issue 1 Answer
HTML5 target : Codepage 1252 not supported 1 Answer
Unity Task not working with target Universal Windows Platform,Use System.Threading.Tasks on UWP 0 Answers
Unable to debug .NET 4.x 0 Answers