gpt4 book ai didi

xml - WCF 契约(Contract)第一个 : No methods are exposed

转载 作者:数据小太阳 更新时间:2023-10-29 02:08:15 25 4
gpt4 key购买 nike

我收到了带有一堆 XSD 的 WSDL,我正在使用它们来创建 WCF 服务。我正在使用 svcutil.exe 生成服务类,基本上一切正常 - 除了服务不公开任何方法。

从 svcutil 生成的 .cs 文件包含以下接口(interface):

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
[System.ServiceModel.ServiceContractAttribute(Namespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/1/port", ConfigurationName="DistributionReceiverWebServicePort")]
public interface DistributionReceiverWebServicePort
{

[System.ServiceModel.OperationContractAttribute(Action="", ReplyAction="*")]
[System.ServiceModel.FaultContractAttribute(typeof(serviceplatformen.dk.xml.wsdl.soap11.DistributionService._1.types.TransportkvitteringType), Action="", Name="TransportKvittering", Namespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/1/types")]
[System.ServiceModel.XmlSerializerFormatAttribute()]
FordelingsobjektModtagResponse FordelingsobjektModtag(FordelingsobjektModtagRequest request);
}

有问题的类型如下所示:

[System.CodeDom.Compiler.GeneratedCodeAttribute("svcutil", "4.0.30319.33440")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/1/types")]
public partial class ForretningskvitteringType
{

private ForretningsValideringsKodeType forretningsValideringsKodeField;

private string begrundelseField;

private FejlType[] fejlListeField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Order=1)]
public string Begrundelse
{
get
{
return this.begrundelseField;
}
set
{
this.begrundelseField = value;
}
}

...
}

我注意到没有任何类型是用 DataContract/DataMember 属性修饰的。这是必需的,还是类型的其他属性涵盖了它们?

我的服务(没有任何操作)暴露的 WSDL 是这样的:

<?xml version="1.0" encoding="utf-8"?>
<wsdl:definitions name="FKService" targetNamespace="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/1/port" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsam="http://www.w3.org/2007/05/addressing/metadata" xmlns:wsx="http://schemas.xmlsoap.org/ws/2004/09/mex" xmlns:wsap="http://schemas.xmlsoap.org/ws/2004/08/addressing/policy" xmlns:msc="http://schemas.microsoft.com/ws/2005/12/wsdl/contract" xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://serviceplatformen.dk/xml/wsdl/soap11/DistributionService/1/port" xmlns:wsa10="http://www.w3.org/2005/08/addressing" xmlns:wsaw="http://www.w3.org/2006/05/addressing/wsdl" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing">
<wsp:Policy wsu:Id="MetadataExchangeHttpBinding_DistributionReceiverWebServicePort_policy">
<wsp:ExactlyOne>
<wsp:All>
<wsaw:UsingAddressing/>
</wsp:All>
</wsp:ExactlyOne>
</wsp:Policy>
<wsdl:types/>
<wsdl:portType name="DistributionReceiverWebServicePort"/>
<wsdl:binding name="BasicHttpBinding_DistributionReceiverWebServicePort" type="tns:DistributionReceiverWebServicePort">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
</wsdl:binding>
<wsdl:binding name="MetadataExchangeHttpBinding_DistributionReceiverWebServicePort" type="tns:DistributionReceiverWebServicePort">
<wsp:PolicyReference URI="#MetadataExchangeHttpBinding_DistributionReceiverWebServicePort_policy"/>
<soap12:binding transport="http://schemas.xmlsoap.org/soap/http"/>
</wsdl:binding>
<wsdl:service name="FKService">
<wsdl:port name="BasicHttpBinding_DistributionReceiverWebServicePort" binding="tns:BasicHttpBinding_DistributionReceiverWebServicePort">
<soap:address location="http://localhost:8082/FKService/"/>
</wsdl:port>
<wsdl:port name="MetadataExchangeHttpBinding_DistributionReceiverWebServicePort" binding="tns:MetadataExchangeHttpBinding_DistributionReceiverWebServicePort">
<soap12:address location="http://localhost:8082/FKService/mex"/>
<wsa10:EndpointReference>
<wsa10:Address>http://localhost:8082/FKService/mex</wsa10:Address>
</wsa10:EndpointReference>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

我想我遗漏了一些非常明显的东西,但是什么?

最佳答案

显然 svcutil 将 ReplyAction="*"添加到操作合约中,这导致了奇怪的行为。

删除 OperationContractAttribute 的规范后,问题就消失了。

[System.ServiceModel.ServiceContractAttribute(Namespace="http://tempuri.org/xml/wsdl/soap11/DistributionService/1/port", ConfigurationName="DistributionReceiverWebServicePort")]
public interface DistributionReceiverWebServicePort
{
[System.ServiceModel.OperationContractAttribute(Action="")]
[System.ServiceModel.FaultContractAttribute(typeof(TransportkvitteringType), Action="", Name="TransportKvittering", Namespace="http://tempuri.org/xml/wsdl/soap11/DistributionService/1/types")]
[System.ServiceModel.XmlSerializerFormatAttribute()]
FordelingsobjektModtagResponse FordelingsobjektModtag(FordelingsobjektModtagRequest request);
}

另见

https://shishkin.wordpress.com/2007/03/21/wcf-actions-asterisk-and-metadata/

https://social.msdn.microsoft.com/Forums/vstudio/en-US/41f5fe72-3ab3-4741-867e-a93119fe62aa/svcutil-generates-replyaction

关于xml - WCF 契约(Contract)第一个 : No methods are exposed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28365682/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com