【问题标题】:WCF metadata missing operationsWCF 元数据缺少操作
【发布时间】:2010-11-18 12:39:23
【问题描述】:

我在 Visual Studio 中运行了一个简单的 Web 服务。如果我尝试查看元数据,则会丢失有关操作的信息,因此 svcutil 会生成没有任何方法的客户端代码。我的设置有什么问题吗?

    <system.serviceModel>
    <bindings>
        <basicHttpBinding>
            <binding name="FCRPublishSOAP" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard" maxBufferSize="65536" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered" useDefaultWebProxy="true">
                <readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384"/>
                <security mode="None">
                    <transport clientCredentialType="None" proxyCredentialType="None" realm=""/>
                    <message clientCredentialType="UserName" algorithmSuite="Default"/>
                </security>
            </binding>
        </basicHttpBinding>
    </bindings>
    <services>
        <service name="Test.Publish.FCRPublish" behaviorConfiguration="SimpleServiceBehavior">
            <endpoint address="FCRPublish" behaviorConfiguration="" binding="basicHttpBinding" bindingConfiguration="FCRPublishSOAP" contract="IFCRPublish"/>
    <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
  </service>
    </services>
<behaviors>
  <serviceBehaviors>
    <behavior name="SimpleServiceBehavior">
      <serviceMetadata httpGetEnabled="True" policyVersion="Policy15" />
    </behavior>
  </serviceBehaviors>
</behaviors>

界面:

    [System.ServiceModel.ServiceContractAttribute(Namespace="http://Test/Publish", ConfigurationName="IFCRPublish")]
public interface IFCRPublish
{

    // CODEGEN: Generating message contract since the operation PublishNotification is neither RPC nor document wrapped.
    [System.ServiceModel.OperationContractAttribute(Action="http://Test/PublishNotification", ReplyAction="*")]
    PublishNotificationResponse1 PublishNotification(PublishNotificationRequest1 request);
}

回复:

    [System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class PublishNotificationResponse1
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://Test/PublishTypes", Order=0)]
    public PublishNotificationResponse PublishNotificationResponse;

    public PublishNotificationResponse1()
    {
    }

    public PublishNotificationResponse1(PublishNotificationResponse PublishNotificationResponse)
    {
        this.PublishNotificationResponse = PublishNotificationResponse;
    }
}

请求:

    [System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "3.0.0.0")]
[System.ServiceModel.MessageContractAttribute(IsWrapped=false)]
public partial class PublishNotificationRequest1
{

    [System.ServiceModel.MessageBodyMemberAttribute(Namespace="http://Test/PublishTypes", Order=0)]
    public PublishNotification PublishNotification;

    public PublishNotificationRequest1()
    {
    }

    public PublishNotificationRequest1(PublishNotification PublishNotification)
    {
        this.PublishNotification = PublishNotification;
    }
}

这是我收到的元数据:

<wsdl:import namespace="http://Test/Publish" location="http://localhost:3992/FCRPublish.svc?wsdl=wsdl0"/>
<wsdl:types/>
<wsdl:binding name="BasicHttpBinding_IFCRPublish" type="i0:IFCRPublish">
    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
</wsdl:binding>
<wsdl:service name="FCRPublish">
    <wsdl:port name="BasicHttpBinding_IFCRPublish" binding="tns:BasicHttpBinding_IFCRPublish">
        <soap:address location="http://localhost:3992/FCRPublish.svc"/>
    </wsdl:port>
</wsdl:service>

我的手术去哪儿了?

【问题讨论】:

  • PublishNotificationResponse1DataContract 属性吗?
  • 否,但它具有 MessageContract 属性。我将编辑帖子以包含请求和响应对象。

标签: c# .net wcf metadata


【解决方案1】:

解决了。为 OperationContract 设置 ReplyAction="*" 意味着 WsdlExporter(发布元数据)将忽略该操作。设置任何其他值都会修复它。

让我困扰的是 svcutil 默认会设置 replyaction 为 * 这意味着默认情况下 svcutil 创建的服务的元数据被有效地破坏了。

【讨论】:

  • 很好地找到了这个。万分感谢。我也在使用 WCSF Blue 工具来创建客户端。
  • 我也遇到了这个问题……一定有原因,这只是浪费了我一个下午。
【解决方案2】:

尝试从您的 enpoint 的地址中删除 FCRPublish...您的 mex 端点在那里并且看起来还可以,所以我相信它应该可以工作

【讨论】:

  • 仔细查看您的代码,我从来没有添加过 MessageBodyMemberAttribute 而没有 MessageHeaderAttribute ,您可以添加一个以防万一吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-02-22
  • 1970-01-01
  • 2017-06-16
  • 1970-01-01
  • 2015-12-19
相关资源
最近更新 更多