从 WCF 中的 WSDL 生成代码不断返回消息与默认值不匹配
好吧,这让我发疯。我一直在尝试从预定义的 wsdl 构建服务实现代码,并且它始终在服务契约/接口上返回一条消息:
// CODEGEN: Generating message contract since the wrapper name (GetMetricsRequest) of message GetMetricsRequest does not match the default value (GetMetrics)
[System.ServiceModel.OperationContractAttribute(Action="GetMetrics", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
GetMetricsResponse GetMetrics(GetMetricsRequest request);
我尝试使用 svcutil.exe 和 WSCF 的生成服务代码向导来执行此操作,并且两者都返回相同的结果。
下面是我正在使用的 WSDL。我已经在这里添加了类型,我确实将它们分解为单独的 xsd,只是不想同时发布两者。使用此 wsdl(嵌入所有类型)也会产生相同的问题。
我已经阅读了这篇博文(http://pzf.fremantle.org/2007/05 /handlign.html),这就是我能找到的关于这个问题的所有内容。我想我已经完成了它所说的一切,但仍然遇到问题。
还有其他人遇到过这个吗?这非常令人气愤,也许我错过了一些明显的事情。任何帮助将不胜感激。
<wsdl:definitions
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="urn:MyNameSpace:V1_0"
targetNamespace="urn:MyNameSpace:V1_0">
<wsdl:types>
<xs:schema targetNamespace="urn:MyNameSpace:V1_0">
<xs:element name="GetMetricsRequest">
<xs:complexType>
<xs:sequence>
<xs:element nillable="true" name="GetMetricRequestElement" type="tns:GetMetricRequestType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetMetricResponse">
<xs:complexType>
<xs:sequence>
<xs:element nillable="true" maxOccurs="unbounded" name="GetMetricResponseElement" type="tns:GetMetricResponseType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="GetMetricResponseType">
<xs:sequence>
<xs:element nillable="true" name="Metrics" type="tns:MetricsType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="GetMetricRequestType">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="MetricCriteria" nillable="true" type="tns:MetricCriteriaType"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="AvailableMetricType">
<xs:restriction base="xs:string">
<xs:enumeration value="MetricType1"/>
<xs:enumeration value="MetricType2"/>
<xs:enumeration value="MetricType3"/>
<xs:enumeration value="MetricType4"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="AvailableMetricsType">
<xs:sequence>
<xs:element minOccurs="1" nillable="true" maxOccurs="unbounded" name="MetricType" type="tns:AvailableMetricType"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="MetricDimensionType">
<xs:restriction base="xs:string">
<xs:enumeration value="Store"/>
<xs:enumeration value="Workgroup"/>
<xs:enumeration value="BusinessDate"/>
<xs:enumeration value="JobClass"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="MetricDimensionsType">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" nillable="true" name="MetricDimension" type="tns:MetricDimensionType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="MetricCriteriaType">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="storeNumber" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="workgroup" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="jobClass" nillable="true" type="xs:string"/>
<xs:element maxOccurs="1" nillable="true" name="dateStart" type="xs:dateTime"/>
<xs:element maxOccurs="1" nillable="true" name="dateEnd" type="xs:dateTime"/>
<xs:element maxOccurs="1" name="dimensions" nillable="true" type="tns:MetricDimensionsType"/>
<xs:element maxOccurs="1" name="metricTypes" nillable="true" type="tns:AvailableMetricsType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="MetricType">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="businessDate" nillable="true" type="xs:dateTime"/>
<xs:element minOccurs="0" maxOccurs="1" name="store" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="workgroup" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="jobClass" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="metricValue" nillable="true" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="MetricsType">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Metric" nillable="true" type="tns:MetricType"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="GetMetricsRequestMessage">
<wsdl:part name="parameters" element="tns:GetMetricsRequest"/>
</wsdl:message>
<wsdl:message name="GetMetricsResponseMessage">
<wsdl:part name="parameters" element="tns:GetMetricResponse"/>
</wsdl:message>
<wsdl:portType name="Metric">
<wsdl:operation name="GetMetrics">
<wsdl:input message="tns:GetMetricsRequestMessage"/>
<wsdl:output message="tns:GetMetricsResponseMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MetricService" type="tns:Metric">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="GetMetrics">
<soap:operation soapAction="GetMetrics" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Metric">
<wsdl:port name="GetMetrics" binding="tns:MetricService">
<soap:address location="http://myurl/myproj/1.0/MyService.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
谢谢 marc_s,
好的,这似乎有效。这只是响应类型中缺少一个“s”。卫生部!
现在服务代码似乎生成得很好,但是当我浏览到我的服务时,没有数据契约/xsd,并且 wsdl 上没有任何操作。
它看起来就像:
<wsdl:definitions name="MetricServiceImplementation" targetNamespace="http://tempuri.org/">
<wsdl:import namespace="urn:GiantEagle:Services:Systems::Metric:V1_0" location="http://localhost:2814/Services/MetricService.svc?wsdl=wsdl0"/>
<wsdl:types/>
<wsdl:binding name="BasicHttpBinding_MetricService" type="i0:MetricService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
</wsdl:binding>
<wsdl:service name="MetricServiceImplementation">
<wsdl:port name="BasicHttpBinding_MetricService" binding="tns:BasicHttpBinding_MetricService">
<soap:address location="http://localhost:2814/Services/MetricService.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
我希望它看起来像我生成代码的 wsdl,不是吗?
Ok, this is driving me insane. I've been trying to build service implementation code from a predefined wsdl and it is consistently returning a message on the service contract/interface:
// CODEGEN: Generating message contract since the wrapper name (GetMetricsRequest) of message GetMetricsRequest does not match the default value (GetMetrics)
[System.ServiceModel.OperationContractAttribute(Action="GetMetrics", ReplyAction="*")]
[System.ServiceModel.XmlSerializerFormatAttribute(SupportFaults=true)]
GetMetricsResponse GetMetrics(GetMetricsRequest request);
I've tried to do this using svcutil.exe and WSCF's Generate Service code wizard, and both return the same result.
Below is the WSDL I'm using. I've added the types in here, I do have them broken out into a seperate xsd, just didn't want to post both. Using this wsdl(with all types embedded) also generates the same problems.
I've reviewed this blog post(http://pzf.fremantle.org/2007/05/handlign.html), it's about all I could find regarding this problem. I think I've done everything it says to do, but am still having issues.
Has anyone else come across this? It's very infuriating, maybe I'm missing something obvious. Any help will be greatly appreciated.
<wsdl:definitions
xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tns="urn:MyNameSpace:V1_0"
targetNamespace="urn:MyNameSpace:V1_0">
<wsdl:types>
<xs:schema targetNamespace="urn:MyNameSpace:V1_0">
<xs:element name="GetMetricsRequest">
<xs:complexType>
<xs:sequence>
<xs:element nillable="true" name="GetMetricRequestElement" type="tns:GetMetricRequestType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="GetMetricResponse">
<xs:complexType>
<xs:sequence>
<xs:element nillable="true" maxOccurs="unbounded" name="GetMetricResponseElement" type="tns:GetMetricResponseType"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:complexType name="GetMetricResponseType">
<xs:sequence>
<xs:element nillable="true" name="Metrics" type="tns:MetricsType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="GetMetricRequestType">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="1" name="MetricCriteria" nillable="true" type="tns:MetricCriteriaType"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="AvailableMetricType">
<xs:restriction base="xs:string">
<xs:enumeration value="MetricType1"/>
<xs:enumeration value="MetricType2"/>
<xs:enumeration value="MetricType3"/>
<xs:enumeration value="MetricType4"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="AvailableMetricsType">
<xs:sequence>
<xs:element minOccurs="1" nillable="true" maxOccurs="unbounded" name="MetricType" type="tns:AvailableMetricType"/>
</xs:sequence>
</xs:complexType>
<xs:simpleType name="MetricDimensionType">
<xs:restriction base="xs:string">
<xs:enumeration value="Store"/>
<xs:enumeration value="Workgroup"/>
<xs:enumeration value="BusinessDate"/>
<xs:enumeration value="JobClass"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="MetricDimensionsType">
<xs:sequence>
<xs:element minOccurs="1" maxOccurs="unbounded" nillable="true" name="MetricDimension" type="tns:MetricDimensionType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="MetricCriteriaType">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="storeNumber" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="workgroup" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="jobClass" nillable="true" type="xs:string"/>
<xs:element maxOccurs="1" nillable="true" name="dateStart" type="xs:dateTime"/>
<xs:element maxOccurs="1" nillable="true" name="dateEnd" type="xs:dateTime"/>
<xs:element maxOccurs="1" name="dimensions" nillable="true" type="tns:MetricDimensionsType"/>
<xs:element maxOccurs="1" name="metricTypes" nillable="true" type="tns:AvailableMetricsType"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="MetricType">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="1" name="businessDate" nillable="true" type="xs:dateTime"/>
<xs:element minOccurs="0" maxOccurs="1" name="store" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="workgroup" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="jobClass" nillable="true" type="xs:string"/>
<xs:element minOccurs="0" maxOccurs="1" name="metricValue" nillable="true" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="MetricsType">
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="Metric" nillable="true" type="tns:MetricType"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
</wsdl:types>
<wsdl:message name="GetMetricsRequestMessage">
<wsdl:part name="parameters" element="tns:GetMetricsRequest"/>
</wsdl:message>
<wsdl:message name="GetMetricsResponseMessage">
<wsdl:part name="parameters" element="tns:GetMetricResponse"/>
</wsdl:message>
<wsdl:portType name="Metric">
<wsdl:operation name="GetMetrics">
<wsdl:input message="tns:GetMetricsRequestMessage"/>
<wsdl:output message="tns:GetMetricsResponseMessage"/>
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="MetricService" type="tns:Metric">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<wsdl:operation name="GetMetrics">
<soap:operation soapAction="GetMetrics" style="document"/>
<wsdl:input>
<soap:body use="literal"/>
</wsdl:input>
<wsdl:output>
<soap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="Metric">
<wsdl:port name="GetMetrics" binding="tns:MetricService">
<soap:address location="http://myurl/myproj/1.0/MyService.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
Thanks marc_s,
Ok, that seemed to work. It was just a missing 's' in the response type. DOH!
Now the service code seems to be generating fine, but when I browse to my service there is no data contract/xsd's and there are no operations on the wsdl.
It just looks like:
<wsdl:definitions name="MetricServiceImplementation" targetNamespace="http://tempuri.org/">
<wsdl:import namespace="urn:GiantEagle:Services:Systems::Metric:V1_0" location="http://localhost:2814/Services/MetricService.svc?wsdl=wsdl0"/>
<wsdl:types/>
<wsdl:binding name="BasicHttpBinding_MetricService" type="i0:MetricService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
</wsdl:binding>
<wsdl:service name="MetricServiceImplementation">
<wsdl:port name="BasicHttpBinding_MetricService" binding="tns:BasicHttpBinding_MetricService">
<soap:address location="http://localhost:2814/Services/MetricService.svc"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>
I would expect it to look like the wsdl I generated the code from, no?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个 - WSDL 中的请求和响应消息应该
所以尝试将 WSDL 更改为:
并更新您的 portType:
这有帮助吗?
如果不是:尝试更新 XSD 中的实际
以匹配相同的模式 - 请求类型必须与您调用的操作相同,响应对象必须是 (方法名称)响应。Try this - your request and response messages in WSDL should be
So try changing your WSDL to:
and also update your portType:
Does that help at all?
If not: try updating your actual
<xs:element>
in your XSD to match the same pattern - the request type must be the same as the operation you're calling, the response object must be (MethodName)Response .删除
OperationContract
的ReplyAction("*")
中的"*"
Remove the
"*"
in theReplyAction("*")
of theOperationContract