久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為非托管 C++ 客戶端創建 WCF 服務

Create WCF service for unmanaged C++ clients(為非托管 C++ 客戶端創建 WCF 服務)
本文介紹了為非托管 C++ 客戶端創建 WCF 服務的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我需要讓非托管 Windows C++ 客戶端與 WCF 服務對話.C++ 客戶端可以在 Win2000 及更高版本上運行.我可以控制 WCF 服務和正在使用的 C++ API.由于它用于專有應用程序,因此最好盡可能使用 Microsoft 的東西,絕對不是 GNU 許可的 API.那些已經開始工作的人,你能分享一個如何讓它工作的分步過程嗎?

I need to get unmanaged Windows C++ clients to talk to a WCF service. C++ clients could be running on Win2000 and later. I have a control over both WCF service and which C++ API is being used. Since it's for a proprietary application, it is preferable to use Microsoft stuff where possible, definitely not GNU licensed APIs. Those of you who have it working, can you share a step-by-step process how to make it working?

到目前為止,我已經研究了以下選項:

I have researched following options so far:

  • WWSAPI - 不好,不能在 Win 2000 客戶端上運行.
  • ATL 服務器,使用 以下指南 作為參考.我遵循了概述的步驟(刪除策略引用并扁平化 WSDL),但是生成的 WSDL 仍然不能被 sproxy 使用
  • WWSAPI - not good, will not work on Win 2000 clients.
  • ATL Server, used following guide as a reference. I followed the steps outlined (remove policy refs and flatten WSDL), however the resulting WSDL is still not usable by sproxy

還有什么想法嗎?請僅在您自己實際使用時才回答.

Any more ideas? Please answer only if you actually have it working yourself.

Edit1:對于我可能感到困惑的任何人,我深表歉意:我正在尋找一種從沒有 .NET 的客戶端調用 WCF 服務的方法框架已安裝,因此不能使用基于 .NET 的幫助程序庫,它必須是純非托管 C++

Edit1: I apologize for anyone who I might have confused: what I was looking for was a way to call WCF service from client(s) where no .NET framework is installed, so using .NET-based helper library is not an option, it must be pure unmanaged C++

推薦答案

對于那些有興趣的人,我找到了一個半工作的 ATL Server 解決方案.以下是主機代碼,注意它使用的是 BasicHttpBinding,這是唯一一個與 ATL Server 一起工作的代碼:

For those who are interested, I found one semi-working ATL Server solution. Following is the host code, notice it is using BasicHttpBinding, it's the only one which works with ATL Server:

        var svc =  new Service1();
        Uri uri = new Uri("http://localhost:8200/Service1");
        ServiceHost host = new ServiceHost(typeof(Service1), uri);

        var binding = new BasicHttpBinding();
        ServiceEndpoint endpoint = host.AddServiceEndpoint(typeof(IService1), binding, uri);
        endpoint.Behaviors.Add(new InlineXsdInWsdlBehavior());

        host.Description.Behaviors.Add(new ServiceMetadataBehavior() { HttpGetEnabled = true });
        var mex = host.AddServiceEndpoint(typeof(IMetadataExchange), MetadataExchangeBindings.CreateMexHttpBinding(), "mex");
        host.Open();

        Console.ReadLine();

可以在此處找到 InlineXsdInWsdlBehavior 的代碼.需要對 InlineXsdInWsdlBehavior 進行一項重要更改,以便在涉及復雜類型時與 sproxy 一起正常工作.它是由 sproxy 中的錯誤引起的,它沒有正確確定名稱空間別名的范圍,因此 wsdl 不能有重復的名稱空間別名,否則 sproxy 會失敗.以下是需要更改的功能:

code for InlineXsdInWsdlBehavior could be found here . One important change needs to be done to the InlineXsdInWsdlBehavior in order for it to work properly with sproxy when complex types are involved. It is caused by the bug in sproxy, which does not properly scope the namespace aliases, so wsdl cannot have repeating namespace aliases or sproxy will crap out. Here's the functions which needs to change:

    public void ExportEndpoint(WsdlExporter exporter, WsdlEndpointConversionContext context)
    {
        int tnsCount = 0;

        XmlSchemaSet schemaSet = exporter.GeneratedXmlSchemas;

        foreach (WsdlDescription wsdl in exporter.GeneratedWsdlDocuments)
        {
            //
            // Recursively find all schemas imported by this wsdl
            // and then add them. In the process, remove any
            // <xsd:imports/>
            //
            List<XmlSchema> importsList = new List<XmlSchema>();
            foreach (XmlSchema schema in wsdl.Types.Schemas)
            {
                AddImportedSchemas(schema, schemaSet, importsList, ref tnsCount);
            }
            wsdl.Types.Schemas.Clear();
            foreach (XmlSchema schema in importsList)
            {
                RemoveXsdImports(schema);
                wsdl.Types.Schemas.Add(schema);
            }
        }
    }


    private void AddImportedSchemas(XmlSchema schema, XmlSchemaSet schemaSet, List<XmlSchema> importsList, ref int tnsCount)
    {
        foreach (XmlSchemaImport import in schema.Includes)
        {
            ICollection realSchemas = schemaSet.Schemas(import.Namespace);
            foreach (XmlSchema ixsd in realSchemas)
            {
                if (!importsList.Contains(ixsd))
                {
                    var new_namespaces = new XmlSerializerNamespaces();
                    foreach (var ns in ixsd.Namespaces.ToArray())
                    {
                        var new_pfx = (ns.Name == "tns") ? string.Format("tns{0}", tnsCount++) : ns.Name;
                        new_namespaces.Add(new_pfx, ns.Namespace);
                    }

                    ixsd.Namespaces = new_namespaces;
                    importsList.Add(ixsd);
                    AddImportedSchemas(ixsd, schemaSet, importsList, ref tnsCount);
                }
            }
        }
    }

下一步是生成C++頭文件:

Next step is to generate C++ header:

sproxy.exe /wsdl http://localhost:8200/Service1?wsdl

然后C++程序看起來像這樣:

and then C++ program looks like this:

using namespace Service1;

CoInitializeEx( NULL, COINIT_MULTITHREADED  );

{
    CService1T<CSoapWininetClient> cli;
    cli.SetUrl( _T("http://localhost:8200/Service1") );

    HRESULT hr = cli.HelloWorld(); //todo: analyze hr
}

CoUninitialize();
return 0;

生成的 C++ 代碼可以很好地處理復雜類型,只是它不能將 NULL 分配給對象.

Resulting C++ code handles complex types pretty decently, except that it cannot assign NULL to the objects.

這篇關于為非托管 C++ 客戶端創建 WCF 服務的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

What do compilers do with compile-time branching?(編譯器如何處理編譯時分支?)
Can I use if (pointer) instead of if (pointer != NULL)?(我可以使用 if (pointer) 而不是 if (pointer != NULL) 嗎?)
Checking for NULL pointer in C/C++(在 C/C++ 中檢查空指針)
Math-like chaining of the comparison operator - as in, quot;if ( (5lt;jlt;=1) )quot;(比較運算符的數學式鏈接-如“if((5<j<=1)))
Difference between quot;if constexpr()quot; Vs quot;if()quot;(“if constexpr()之間的區別與“if())
C++, variable declaration in #39;if#39; expression(C++,if 表達式中的變量聲明)
主站蜘蛛池模板: 久久久久久久国产 | 精品亚洲一区二区三区四区五区高 | 亚洲九九 | 亚洲天堂免费在线 | 国产在线精品一区二区三区 | 国产精品久久久久久久久免费软件 | 亚洲最大看片网站 | 精品国产乱码久久久久久丨区2区 | 成人欧美日韩一区二区三区 | 日本特黄a级高清免费大片 特黄色一级毛片 | 久久亚洲精品视频 | av在线电影网站 | 亚洲综合无码一区二区 | 午夜精品久久久久久久久久久久久 | 久久久新视频 | 一级做a爰片久久毛片免费看 | 国产精品日韩欧美一区二区三区 | 91精品国产日韩91久久久久久 | 成人欧美一区二区三区黑人孕妇 | 日中文字幕在线 | 在线激情视频 | 狠狠操在线 | 亚洲乱码国产乱码精品精的特点 | 久久精品国产亚洲a | 成人在线视频免费观看 | 日韩和的一区二区 | 亚洲一区二区三区乱码aⅴ 四虎在线视频 | 精品久久久久香蕉网 | 亚洲乱码一区二区三区在线观看 | 国产精品久久久久久久久久三级 | 国产视频不卡一区 | 中文字幕乱码视频32 | 久久最新 | 国产精品自产av一区二区三区 | 国产精品视频免费观看 | 亚洲国产精品人人爽夜夜爽 | 欧美8一10sex性hd | 久久久蜜臀国产一区二区 | 国产精品1区2区 | 狠狠躁夜夜躁人人爽天天高潮 | 久久久精品在线 |