1

我正在设计一个应用程序以在 Microsoft HoloLens 上运行,使用 Unity 进行用户交互。应用程序连接到 asmx Web 服务以检索数据。

我有一个 C# 测试程序来测试来自 web 服务的连接和数据检索。

然后我按照本教程生成了一个基于 webservice wsdl ( https://www.youtube.com/watch?v=AifcMzEbKnA )的 dll

如果使用以下脚本生成 dll:

@echo off
if exist "Service.xml" (
del MyOwnWS.wsdl
echo Rename
rename Service.xml MyOwnWS.wsdl
echo.
)
echo WSDL
call wsdl MyOwnWS.wsdl -o:MyOwnWS.cs
echo.
echo DMCS
call dmcs /target:library MyOwnWS.cs -r:System.Web.Services,System.Data
echo.
echo Done

我添加了 system.Data 因为我的 web 服务从数据库返回 DataSet 数据。

我将该 dll 放在 Unity 项目的 Assets 文件夹中。我还必须在其中删除 System.Data.dll、System.dll 和 System.Web.Services.dll(从 C:\Program Files\Unity Hololens 5.4.0b16-HTP\Editor\Data\Mono\lib 获取它们\mono\unity 文件夹)

当我使用 Unity 编辑器时,我的应用程序连接到 Web 服务并毫无问题地检索数据。

下一步,我按照本教程从 Unity 制作 HoloLens 应用程序 ( http://hololenshelpwebsite.com/Blog/EntryId/1006/HoloLens-Hello-World )

虽然它适用于他们自己的 Hello World,但当我尝试从统一构建自己的项目时,我收到以下错误:

错误 CS1703:已导入具有等效标识的多个程序集:'C:\Users\UserA\.nuget\packages\Microsoft.NETCore.Portable.Compatibility\1.0.0\ref\netcore50\System.dll' 和 'J:\工作\MyTestUnity\Assets\System.dll'。删除重复的引用之一。版权所有 (C) Microsoft Corporation。保留所有权利。Microsoft (R) Visual C# 编译器版本 1.3.1.60616

于是我在Editor下添加了一个ProjectFileHook.cs文件,内容如下:

using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using UnityEditor;
using SyntaxTree.VisualStudio.Unity.Bridge;
using UnityEngine;

// http://forum.unity3d.com/threads/missing-c-references-to-system-data.11361/
// https://visualstudiogallery.msdn.microsoft.com/8d26236e-4a64-4d64-8486-7df95156aba9

[InitializeOnLoad]
public class ProjectFileHook
{
    // necessary for XLinq to save the xml project file in utf8
    class Utf8StringWriter : StringWriter
    {
        public override Encoding Encoding
        {
            get { return Encoding.UTF8; }
        }
    }

    static void ProcessNodesWithIncludeAttribute(XDocument document, string localName, string includeValue, Action<XElement> action)
    {
        var nodes = document
            .Descendants()
            .Where(p => p.Name.LocalName == localName);

        foreach (var node in nodes)
        {
            var xa = node.Attribute("Include");
            if (xa != null && !string.IsNullOrEmpty(xa.Value) && string.Equals(xa.Value, includeValue))
            {
                action(node);
            }
        }        
    }

    // Remove System.Data from project (not from file system so Unity can compile properly)
    static void RemoveFileFromProject(XDocument document, string fileName)
    {
        ProcessNodesWithIncludeAttribute(document, "None", fileName, element => element.Remove());        
    }

    // Adjust references, by using the default framework assembly instead of local file (remove the HintPath)
    static void RemoveHintPathFromReference(XDocument document, string assemblyName)
    {
        ProcessNodesWithIncludeAttribute(document, "Reference", assemblyName, element => element.Nodes().Remove());        
    }

    static ProjectFileHook()
    {
        ProjectFilesGenerator.ProjectFileGeneration += (string name, string content) =>
        {
            var document = XDocument.Parse(content);

            RemoveFileFromProject(document, @"Assets\System.Data.dll");
            RemoveHintPathFromReference(document, "System.Data");

            RemoveFileFromProject(document, @"Assets\System.Web.Services.dll");
            RemoveHintPathFromReference(document, "System.Web.Services");

            RemoveFileFromProject(document, @"Assets\System.dll");
            RemoveHintPathFromReference(document, "System");

            var str = new Utf8StringWriter();
            document.Save(str);

            return str.ToString();
        };
    }
}

但看起来这没有任何作用。

我现在对如何解决这个问题感到迷茫,我真的需要专家的帮助来解决这个问题。

4

1 回答 1

0

所以...看起来我们不能再像那样使用 WSDL webservice 了。微软不久前在更新中放弃了对它的支持。我看过多篇关于它的文章,但我忘了保留书签。因此,如果您想查找它,您将必须阅读 WUP 文档。

相反,我们最终使用 UnityWebRequest 和 Coroutines 来处理 Web 服务通信。

我们还必须更新 web 服务以启用 Get/post 调用。

于 2016-08-04T15:03:40.367 回答