我正在尝试向我的项目添加服务引用,但我不断遇到相同的错误。
我使用 SOAP UI 创建了一个看起来不错的模拟服务,然后我尝试向该模拟服务添加一个服务引用,但出现错误:
Warning 14 Custom tool warning: Cannot import wsdl:portType
Detail: An exception was thrown while running a WSDL import extension: System.ServiceModel.Description.DataContractSerializerMessageContractImporter
Error: Schema with target namespace 'urn:oasis:names:tc:dss:1.0:core:schema' could not be found.
XPath to Error Source: //wsdl:definitions[@targetNamespace='http://tempuri.org/esign']/wsdl:portType[@name='EsignServiceSoap11PortType']
在 wsdl 上导入带有命名空间 urn:oasis:names:tc:dss:1.0:core:schema 的模式被加载是:
<wsdl:types>
<schema xmlns="urn:oasis:names:tc:dss:1.0:core:schema">
<import namespace="urn:oasis:names:tc:dss:1.0:core:schema" schemaLocation="oasis-dss-core-schema-v1.0-os.xsd"/>
</schema>
.....
</wsdl:types>
我已经尝试将 schemaLocation 直接链接到与 wsdl 相同的文件夹中的文件,链接到它在私有(private)服务器中发布的 url 和它也发布的公共(public) uri。
我总是遇到同样的错误,我开始觉得我可能搞错了问题的根源。
任何见解将不胜感激。
更新:我在我的 wsdl 文件中注入(inject)了 urn:oasis:names:tc:dss:1.0:core:schema 完整定义,而不是尝试导入它。当我这样做时,SOAP UI 仍然正确地创建模拟服务,但是,当我尝试添加服务引用时,在服务发现期间抛出此错误:
The document was understood, but it could not be processed.
- The WSDL document contains links that could not be resolved.
- DTD is prohibited in this XML document.
Metadata contains a reference that cannot be resolved: 'http://elite8100-3:8088/mockEsignServiceSoap11Binding?WSDL'.
The content type text/html; charset=iso-8859-1 of the response message does not match the content type of the binding (application/soap+xml; charset=utf-8). If using a custom encoder, be sure that the IsContentTypeSupported method is implemented properly. The first 455 bytes of the response were: '<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope">
<soap:Body>
<soap:Fault>
<soap:Code>
<soap:Value>Server</soap:Value>
</soap:Code>
<soap:Reason>
<!--1 or more repetitions:-->
<soap:Text xml:lang="en">Missing operation for soapAction [null] and body element [null] with SOAP Version [SOAP 1.2]</soap:Text>
</soap:Reason>
</soap:Fault>
</soap:Body>
</soap:Envelope>'.
The remote server returned an error: (500) Internal Server Error.
If the service is defined in the current solution, try building the solution and adding the service reference again.
EDIT2:按照答案中的建议,我在尝试创建代理时使用 Fiddler 检查 http 流量。在创建期间,当尝试访问 mockService url 时,Fiddler 上出现 500 内部服务器错误,服务器的响应是“SOAP 版本 [SOAP 1.2] 的 soapAction [null] 和 body 元素 [null] 缺少操作”。
目前,这是我用来创建模拟服务的 WSDL。
<wsdl:types>
<schema xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://www.w3.org/2001/XMLSchema" schemaLocation="http://aplicaciones.serpasa.es/CONTROLAMBIENTAL/oasis-dss-core-schema-v1.0-os.xsd"/>
</schema>
<schema xmlns="http://princast.es/esign/2.0/esign.xsd">
<import namespace="http://princast.es/esign/2.0/esign.xsd" schemaLocation="http://aplicaciones.serpasa.es/CONTROLAMBIENTAL/esign.xsd"/>
</schema>
</wsdl:types>
<wsdl:message name="SignRequestMessage">
<wsdl:part element="dss:SignRequest" name="payload"/>
</wsdl:message>
<wsdl:message name="SignResponseMessage">
<wsdl:part element="dss:SignResponse" name="payload"/>
</wsdl:message>
<wsdl:message name="VerifyRequestMessage">
<wsdl:part element="dss:VerifyRequest" name="payload"/>
</wsdl:message>
<wsdl:message name="VerifyResponseMessage">
<wsdl:part element="dss:VerifyResponse" name="payload"/>
</wsdl:message>
<wsdl:message name="GetSignInfoFromDocumentRequestMessage">
<wsdl:part element="esign:SignInfoRequest" name="payload"/>
</wsdl:message>
<wsdl:message name="GetSignInfoFromDocumentResponseMessage">
<wsdl:part element="esign:SignInfo" name="payload"/>
</wsdl:message>
<wsdl:message name="GetSignConfigurationRequestMessage">
<wsdl:part element="esign:SignConfigurationRequest" name="payload"/>
</wsdl:message>
<wsdl:message name="GetSignConfigurationResponseMessage">
<wsdl:part element="esign:SupportedSignConfiguration" name="payload"/>
</wsdl:message>
<!-- Port -->
<wsdl:portType name="EsignServiceSoap11PortType">
<wsdl:operation name="sign">
<wsdl:input message="impl:SignRequestMessage" name="signRequest"/>
<wsdl:output message="impl:SignResponseMessage" name="signResponse"/>
</wsdl:operation>
<wsdl:operation name="verify">
<wsdl:input message="impl:VerifyRequestMessage" name="verifyRequest"/>
<wsdl:output message="impl:VerifyResponseMessage" name="verifyResponse"/>
</wsdl:operation>
<wsdl:operation name="getSignConfiguration">
<wsdl:input message="impl:GetSignConfigurationRequestMessage" name="getSignConfigurationRequest"/>
<wsdl:output message="impl:GetSignConfigurationResponseMessage" name="getSignConfigurationResponse"/>
</wsdl:operation>
<wsdl:operation name="getSignInfoFromDocument">
<wsdl:input message="impl:GetSignInfoFromDocumentRequestMessage" name="getSignInfoFromDocumentRequest"/>
<wsdl:output message="impl:GetSignInfoFromDocumentResponseMessage" name="getSignInfoFromDocumentResponse"/>
</wsdl:operation>
</wsdl:portType>
<!-- Binding -->
<wsdl:binding name="EsignServiceSoap11Binding" type="impl:EsignServiceSoap11PortType">
<wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
<wsdl:operation name="sign">
<wsdl:documentation>
Realiza una firma digital delegada sobre un
documento segun el estandard OASIS Digital Signature Service (DSS)
</wsdl:documentation>
<wsdlsoap:operation soapAction="urn:sign"/>
<wsdl:input name="signRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="signResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="verify">
<wsdl:documentation>
Verifica una firma digital OASIS Digital
Signature Service (DSS)
</wsdl:documentation>
<wsdlsoap:operation soapAction="urn:verify"/>
<wsdl:input name="verifyRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="verifyResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getSignConfiguration">
<wsdl:documentation>
Obtiene los certificados con los que una
aplicacion en el MC de Firma Digital puede realizar
una firma
</wsdl:documentation>
<wsdlsoap:operation soapAction="urn:getSignConfiguration"/>
<wsdl:input name="getSignConfigurationRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getSignConfigurationResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="getSignInfoFromDocument">
<wsdl:documentation>
Obtiene informacion de un fichero de firma
</wsdl:documentation>
<wsdlsoap:operation soapAction="urn:getSignInfoFromDocument"/>
<wsdl:input name="getSignInfoFromDocumentRequest">
<wsdlsoap:body use="literal"/>
</wsdl:input>
<wsdl:output name="getSignInfoFromDocumentResponse">
<wsdlsoap:body use="literal"/>
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="EsignService">
<wsdl:documentation>
Servicio web de firma digital
</wsdl:documentation>
<wsdl:port binding="impl:EsignServiceSoap11Binding" name="EsignServiceSoap11Port">
<wsdlsoap:address location="http://someexternalsite.com"/>
</wsdl:port>
</wsdl:service>
我已经下载了每个关联的 .xsd 并将它们发布到公共(public)服务器上,我还更改了 schemaLocations 以便它们指向该公共(public)服务器上的地址,但是,问题似乎与 WSDL 结构有关。
最佳答案
更新之前的主要问题一定是你的语法错误。你在哪里说 <schema xmlns="urn:oasis:names:tc:dss:1.0:core:schema">
该工具期待 <schema xmlns="http://www.w3.org/2001/XMLSchema">
.要简单地导入一个外部 XSD 文件,上面的默认 XML 命名空间修复它就是你所需要的。
模式导入/包含可能非常困惑;对于这些情况,当将它们放入 WSDL 中时,正如您所建议的那样,很容易出错,因为这不是简单的剪切和粘贴的情况。例如,某些工具可能无法处理最初基于 xsd:include 的引用;变色龙包含不能在 WSDL 中复制;并且您所有的 xsd:imports 不得使用 schemaLocation 属性。
要解决与损坏的引用相关的问题,我强烈建议使用 HTTP 调试器,例如 Fiddler。它至少会告诉您忘记清理哪些引用,或者您的模拟解决方案未正确设置的任何 HTTP header 。
如果以上内容仍然给您留下一些问题,您将不得不发布修改后的 WSDL。
关于c# - 服务引用未加载 : Schema with target namespace could not be found,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36061707/