c# - WCF 服务引用从 WSDL 生成无效方法

标签 c# wcf web-services visual-studio-2010

这是我第一次尝试使用 WCF,所以我猜我做错了什么。 我正在尝试访问由位于 http://confluence.atlassian.com/rpc/soap-axis/confluenceservice-v1?wsdl 的 WSDL 定义的 soap 服务我正在使用 VS2010,我向我的项目添加了一个服务引用并将其指向那里的 URL(或者更确切地说,我们的内部网安装它),但是当我使用对象浏览器查看服务时,界面上的操作都是没有参数的 void 方法。似乎 WCF 没有正确读取类型信息。它不会给出错误,但会给出大量警告,如下所示:

Warning 1 Custom tool warning: Fault named InvalidSessionException in operation getPermissions cannot be imported. Unsupported WSDL, the fault message part must reference an element. This fault message does not reference an element. If you have edit access to the WSDL document, you can fix the problem by referencing a schema element using the 'element' attribute. Z:\TestLibrary\Service References\Confluence\Reference.svcmap 1 1 TestLibrary

Warning 2 Custom tool warning: The optional WSDL extension element 'body' from namespace 'http://schemas.xmlsoap.org/wsdl/soap/' was not handled. XPath: //wsdl:definitions[@targetNamespace='http://confluence.atlassian.com/rpc/soap-axis/confluenceservice-v1']/wsdl:binding[@name='confluenceservice-v1SoapBinding']/wsdl:operation[@name='getPermissions']/wsdl:input[@name='getPermissionsRequest'] Z:\TestLibrary\Service References\Confluence\Reference.svcmap 1 1 TestLibrary

我做错了什么?我尝试使用选项组合更改服务的配置,但我永远无法正确地从 WSDL 中提取类型。我一直假设 WCF 会自动生成类型类以及服务接口(interface)。我是应该弄清楚 WSDL 中使用的是什么类型并自己创建类和数据协定,还是其他什么?

最佳答案

Hhmm...有趣 - 我从命令行针对您提供的 URL 运行了 svcutil.exe,虽然我收到了大量关于 WSDL 问题的警告,但我也得到了一些代码 -像这样的东西:

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:2.0.50727.4952
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://confluence.atlassian.com/rpc/soap-axis/confluenceservice-v1", ConfigurationName="ConfluenceSoapService")]
public interface ConfluenceSoapService
{
    // CODEGEN: Generating message contract since the wrapper namespace (http://soap.rpc.confluence.atlassian.com) of message getPermissionsRequest does not match the default value (http://confluence.atlassian.com/rpc/soap-axis/confluenceservice-v1)
    [System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
    [System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, Use=System.ServiceModel.OperationFormatUse.Encoded)]
    getPermissionsResponse getPermissions(getPermissionsRequest request);

    // CODEGEN: Generating message contract since the wrapper namespace (http://soap.rpc.confluence.atlassian.com) of message searchRequest does not match the default value (http://confluence.atlassian.com/rpc/soap-axis/confluenceservice-v1)
    [System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
    [System.ServiceModel.XmlSerializerFormatAttribute(Style=System.ServiceModel.OperationFormatStyle.Rpc, Use=System.ServiceModel.OperationFormatUse.Encoded)]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(RemoteException))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(Vector))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(RemotePermission))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(RemoteNodeStatus))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(RemotePageHistory))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(RemoteContentPermission))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(AbstractRemotePageSummary))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(RemoteSpaceSummary))]
    [System.ServiceModel.ServiceKnownTypeAttribute(typeof(RemoteSearchResult))]
    searchResponse search(searchRequest request);

所以我会尝试从命令行使用 svcutil.exe 来生成您的 ConfluenceSoapService.cs 文件,然后使用它与您的 Confluence 服务通信。

关于c# - WCF 服务引用从 WSDL 生成无效方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3789359/

相关文章:

python - 添加对位于共享驱动器上的 .dll 的引用

c# - 将对象名称与数字组合

python - 如何实现在单独的python进程之间共享的队列系统?

web-services - 授权和构建 RESTful 后端的正确方法是什么

C# 和 float 的恶作剧

c# - 将字典添加到另一个字典 C#

c# - 通过消息契约重用类型

wcf - 有没有一种方法可以从MIC流音频并在Silverlight中播放该流

c# - WCF : The EncryptedKey clause was not wrapped with the required encryption token 'System.IdentityModel.Tokens.X509SecurityToken'

Java 网络服务 : SOAP over FTP