5

我在 Eclipse 中用 Java 编写了一个简单的 WSDL Web 服务。以下是该服务的 Java 代码原型:

public static String vriteAnnouncement(String title, String body){
    ...
}

我已经使用 Microsoft 工具为此 WSDL 服务生成了一个代理类,wsdl.exe并使用开发人员命令提示符 Visual Studio 2012 中的以下命令将其设为 dll:

wsdl /l:CS /protocol:SOAP WriteAnnouncement.wsdl
csc /t:library /r:System.Web.Services.dll /r:System.Xml.dll WriteAnnouncementService.cs

在我的 Windows 8 Store 应用程序中,我添加了对此 dll 的引用,然后在 MainPage.xaml.cs 中添加了以下代码:

WriteAnnouncementService was = new WriteAnnouncementService();

当我尝试运行该应用程序时,出现此错误:

类型“System.Web.Services.Protocols.SoapHttpClientProtocol”在未引用的程序集中定义。
您必须添加对程序集“System.Web.Services,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”的引用。
C:\Users...\MainPage.xaml.cs 第 27 行第 13 列

然后我添加了对 System.Web.Service 的引用并重建了应用程序。现在我收到以下错误:

无法解析类型“System.Web.Services.Protocols.WebClientProtocol”引用的程序集“System,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b77a5c561934e089”中的基类或接口“System.ComponentModel.Component” :\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Web.Services.dll

4

2 回答 2

2

您是否有理由使用 wsdl.exe 生成代理?

我不是 bcl 的 Windows 8 存储子集的专家,但我建议使用 svcutil 从已知的 wsdl 生成代理,因为生成的代理支持较新的 Web 服务子系统。生成的代理继承自基类库中的不同类。对我来说,较新的子系统更有可能在受限环境中无缝工作。

于 2013-01-06T20:16:19.923 回答
1

Adding service reverence via "Add Service Reference" solved the problem. enter image description here

enter image description here

But I have an other problem with the generated reference.cs file. There are multiple errrors about ambigous calls.

The call is ambiguous between the following methods or properties: 'GyteKiosk.ServiceReference1.WriteAnnouncementClient.ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint, System.ServiceModel.Description.ClientCredentials)' and 'GyteKiosk.ServiceReference1.WriteAnnouncementClient.ConfigureEndpoint(System.ServiceModel.Description.ServiceEndpoint, System.ServiceModel.Description.ClientCredentials)' Reference.cs 115 13

UPDATE!

I have solved the ambigous call promlem too. Step by step solution for ambigous call:

  1. My service class name was "WriteAnnouncement" and the service method name was "vriteAnnouncement". Changed method name to just "write".
  2. Recreated Web Service in Eclipse without any test client.
  3. Took the WSDL file and placed in project folder.
  4. Deleted previously added service reference and readded service reference. Gave neme to service reference as "WAServRef"

To use service in project:

  1. Add using GyteKiosk.WAServRef; to page code whic you will use service in.
  2. Call your service where you want to use:

        WriteAnnouncementClient wac = new WriteAnnouncementClient();
        Task<GyteKiosk.WAServRef.writeResponse> wres = wac.writeAsync("Gyte Kiosk", "Gyte Kiosk");
        String result = wres.Result.Body.writeReturn;
        this.pageTitle.Text = result;
    
于 2013-01-07T14:29:46.133 回答