Wcf 在WSDL文件中包含架构类型
我手工创建了一个WSDL,它只有一个操作,没有输入参数,也没有输出参数 尝试从此WSDL创建客户端时,我遇到以下错误: 无法导入wsdl:portType 详细信息:运行WSDL导入扩展时引发异常:System.ServiceModel.Description.DataContractSerializerMessageCompactImporter 错误:找不到目标命名空间为“”的架构。 XPath到错误源://wsdl:definitions[@targetNamespace='']/wsdl:portType[@name='GAMEAssociateIntf']C:\toolbox\BlueTest\BloodRedTest\BloodRedTest\ServiceWcf 在WSDL文件中包含架构类型,wcf,web-services,xsd,wsdl,contract-first,Wcf,Web Services,Xsd,Wsdl,Contract First,我手工创建了一个WSDL,它只有一个操作,没有输入参数,也没有输出参数 尝试从此WSDL创建客户端时,我遇到以下错误: 无法导入wsdl:portType 详细信息:运行WSDL导入扩展时引发异常:System.ServiceModel.Description.DataContractSerializerMessageCompactImporter 错误:找不到目标命名空间为“”的架构。 XPath到错误源://wsdl:definitions[@targetNamespace='']/wsdl
类型(将在客户机中使用)需要从WSDL中存在的XML生成。我认为,在添加服务引用时,由于XML中的一些错误,该工具无法创建它。xsd似乎是个问题
创建代理需要在WSDL中做什么更改
注意:我试图包括WSDL本身中定义的xml类型。[架构防御不需要单独的文件]
WSDL
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="GAMEAssociate"
targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
xmlns:tns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsp="http://www.w3.org/ns/ws-policy"
>
<types>
<xsd:schema>
</xsd:schema>
<xsd:element name="myData">
<xsd:complexType />
</xsd:element>
<xsd:element name="myDataResponse">
<xsd:complexType />
</xsd:element>
</types>
<message name="getAllVicePresidentsRequest">
<part element="tns:myData" name="getAllVicePresidentsRequest"/>
</message>
<message name="getAllVicePresidentsResponse">
<part element="tns:myDataResponse" name="getAllVicePresidentsResponse"/>
</message>
<portType name="GAMEAssociateIntf">
<operation name="getAllVicePresidents">
<input message="tns:getAllVicePresidentsRequest"/>
<output message="tns:getAllVicePresidentsResponse"/>
</operation>
</portType>
<binding name="GAMEAssociateIntfBinding" type="tns:GAMEAssociateIntf">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getAllVicePresidents">
<soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest"
style="document"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="GAMEAssociate">
<port binding="tns:GAMEAssociateIntfBinding" name="GAMEAssociateSOAP">
<soap:address location="http://localhost:8014/associateservice/GAMEAssociate.svc"/>
</port>
</service>
</definitions>
<?xml version="1.0" encoding="UTF-8"?>
<definitions name="GAMEAssociate"
targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
xmlns:tns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
xmlns="http://schemas.xmlsoap.org/wsdl/"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:wsp="http://www.w3.org/ns/ws-policy"
>
<types>
<xsd:schema targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" >
<xsd:element name="myData">
<xsd:complexType />
</xsd:element>
<xsd:element name="myDataResponse" nillable="true">
<xsd:complexType />
</xsd:element>
</xsd:schema>
</types>
<message name="getAllVicePresidentsRequest">
<part element="tns:myData" name="getAllVicePresidentsRequest"/>
</message>
<message name="getAllVicePresidentsResponse">
<part element="tns:myDataResponse" name="getAllVicePresidentsResponse"/>
</message>
<portType name="GAMEAssociateIntf">
<operation name="getAllVicePresidents">
<input message="tns:getAllVicePresidentsRequest"/>
<output message="tns:getAllVicePresidentsResponse"/>
</operation>
</portType>
<binding name="GAMEAssociateIntfBinding" type="tns:GAMEAssociateIntf">
<soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<operation name="getAllVicePresidents">
<soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest"
style="document"/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
</operation>
</binding>
<service name="GAMEAssociate">
<port binding="tns:GAMEAssociateIntfBinding" name="GAMEAssociateSOAP">
<soap:address location="http://localhost:8014/associateservice/GAMEAssociate.svc"/>
</port>
</service>
</definitions>
参考资料:
我花了一些时间试图找出问题所在。您的wsdl部分不正确,应该如下所示。有了它,我现在可以用Java生成客户端人工制品
<types>
<schema targetNamespace="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"
xmlns="http://www.w3.org/2001/XMLSchema">
<element name="myData">
<complexType/>
</element>
<element name="myDataResponse">
<complexType/>
</element>
</schema></types>
请求
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/">
<soapenv:Header/>
<soapenv:Body>
<ns:myData/>
</soapenv:Body>
</soapenv:Envelope>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/">
<soapenv:Header/>
<soapenv:Body>
<ns:myData/>
</soapenv:Body>
</soapenv:Envelope>
响应
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<myDataResponse xsi:nil="true" xmlns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"/>
</s:Body>
</s:Envelope>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<myDataResponse xsi:nil="true" xmlns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"/>
</s:Body>
</s:Envelope>
wsi.org有一套验证工具,当然值得一试
使用这些工具的另一个好处是,您可以实际声明符合WSDL规范。。也要感谢@indonknight。下面给出了工作契约WSDL
注1:xsd前缀和targetNamespace位于wsdltype
注2:nillable=“true”用于响应消息中使用的类型
注3:如果您遇到以下异常,请确保契约WSDL中的soapAction
与从WCF服务生成的WSDL完全相同。一些用于生成服务代码的工具可以根据自己的意愿修改SOAP操作
Faultcod:a:ActionNotSupported
Faultstring:由于EndpointDispatcher上的ContractFilter不匹配,无法在接收方处理具有操作“”的消息。这可能是因为合同不匹配(发送方和接收方之间的操作不匹配)或发送方和接收方之间的绑定/安全不匹配。检查发送方和接收方是否具有相同的合同和相同的绑定(包括安全要求,例如消息、传输、无)
SOAP操作-契约WSDL
<soap:operation soapAction="http://www.xmlns.mycompany.com/GAME/wsdl/AssociateIntf/1.4/getAllVicePresidentsRequest"
你说没有输入参数也没有输出参数。但是,我可以看到您的操作正在定义一个输入和一个输出参数。@这些消息都是空的。我认为,我们需要像我没有在C#上工作过中所解释的那样的消息,但是WSDL看起来不错。我登记了SOAPUI,谢谢。您是否能够使用此WSDL以任何编程语言创建服务和客户机?操作是否给出了正确的响应?参考:谢谢。当我用SOAP UI尝试时,myDataResponse
没有出现在响应中,而myData
出现在输入中。知道为什么吗?我用修改过的wsdl创建了SOAPUI项目,还创建了一个模拟服务。然后我得到了这个回复,你是在实际的web服务上启动你的请求吗?如果是这样,您看到了什么输出?我从这个WSDL创建了一个WCF服务。我使用soapui(通过使用WCF生成的WSDL)进行了测试。下面是没有myDataResponse的响应
-太棒了!但是,nillable false的默认值自然会使元素强制通过。看来你的结果正好相反!!“内联模式”链接似乎已断开。
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/">
<soapenv:Header/>
<soapenv:Body>
<ns:myData/>
</soapenv:Body>
</soapenv:Envelope>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<myDataResponse xsi:nil="true" xmlns="http://www.xmlns.mycompany.com/GAME/service/Associate/1.1/"/>
</s:Body>
</s:Envelope>