我正在尝试将带有SOAP消息的服务嵌入到我的Visual Studio项目中。 他们给了我一些说明,我在stackoverflow上看到我必须在Visual Studio中使用wsdl和xsd文件,以便它可以创建我需要的所有类。 问题是,当我尝试将 wsdl 文件添加为服务引用时,它说该文件不存在。我使用提供的 URL 自己搜索它,但它真的不存在。 有什么办法让我可以使用它。
Below is the WSDL statement:
https://www1.gsis.gr/wsicispay/rmt_ws?wsdl
<definitions targetNamespace="http://remittance_ws/rmt_ws.wsdl" name="rmt_ws"
xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://remittance_ws/rmt_ws.wsdl"
xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema>
<xsd:import namespace="http://remittance_ws/rmt_ws.wsdl"
schemaLocation="https://www1.gsis.gr/wsicispay/rmt_ws?xsd=1"/>
</xsd:schema>
</types>
<message name="remittanceXml">
<part name="parameters" element="tns:remittanceXml"/>
</message>
<message name="remittanceXmlResponse">
<part name="parameters" element="tns:remittanceXmlResponse"/>
</message>
<message name="UnsupportedEncodingException">
<part name="fault" element="tns:UnsupportedEncodingException"/>
</message>
<portType name="rmt_ws">
<operation name="remittanceXml">
<input message="tns:remittanceXml"/>
<output message="tns:remittanceXmlResponse"/>
<fault message="tns:UnsupportedEncodingException" name="UnsupportedEncodingException"/>
</operation>
</portType>
<binding name="rmt_wsBinding" type="tns:rmt_ws">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="remittanceXml">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="UnsupportedEncodingException">
<soap:fault name="UnsupportedEncodingException" use="literal"/>
</fault>
</operation>
</binding>
<service name="rmt_ws">
<port name="rmt_ws" binding="tns:rmt_wsBinding">
<soap:address location="https://www1.gsis.gr/wsicispay/rmt_ws"/>
</port>
</service>
</definitions>
这是 XSD
https://www1.gsis.gr/wsicispay/rmt_ws?xsd=1
<xs:schema version="1.0" targetNamespace="http://remittance_ws/rmt_ws.wsdl"
xmlns:tns="http://remittance_ws/rmt_ws.wsdl" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="UnsupportedEncodingException" type="tns:UnsupportedEncodingException"/>
<xs:element name="remittanceXml" type="tns:remittanceXml"/>
<xs:element name="remittanceXmlResponse" type="tns:remittanceXmlResponse"/>
<xs:complexType name="remittanceXml">
<xs:sequence>
<xs:element name="inputXML" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="remittanceXmlResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="UnsupportedEncodingException">
<xs:sequence>
<xs:element name="message" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
Δείγμα μηνύματος:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:rmt="http://remittance_ws/rmt_ws.wsdl">
<soapenv:Header/>
<soapenv:Body>
<rmt:remittanceXml>
<inputXML><remittance><wsTin>Tin</wsTin><wsUser>Username</wsUser><wsPswd
>Pswd</wsPswd><contain><bmrn>16GRIMXXXX00001746</bmrn><blrn>TESTFOR1&
lt;/blrn><bcnt>1</bcnt><bafm>099099099</bafm></contain><contain><bmr
n>16GRIMXXXX00001720</bmrn><blrn>TESTFOR2</blrn><bcnt>2</bcnt><bafm&
gt;099099099</bafm></contain><contain><bmrn>16GRIMXXXX00001738</bmrn><bl
rn>TESTFOR2</blrn><bcnt>2</bcnt><bafm>099099099</bafm></contain></
remittance></inputXML>
</rmt:remittanceXml>
</soapenv:Body>
</soapenv:Envelope>
这些在他们给我的pdf文件中。
编辑: 如果我从服务引用将其添加为文件,它会创建参考电子支付,而不是.cs文件。 当我添加引用时,它只给我一个具有操作 remitanceXML 的服务rmt_ws,没有其他任何内容。 我不知道这是否正确,我应该如何使用它
我将 xsd 部分复制到 wsdl 中,Visual Studio 通过一个操作生成一个服务来发送输入 XML 并返回另一个 XML。我希望,这有所帮助。
rmt_ws.wsdl:
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://remittance_ws/rmt_ws.wsdl" name="rmt_ws" targetNamespace="http://remittance_ws/rmt_ws.wsdl" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xs:schema targetNamespace="http://remittance_ws/rmt_ws.wsdl" version="1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="UnsupportedEncodingException" type="tns:UnsupportedEncodingException" />
<xs:element name="remittanceXml" type="tns:remittanceXml" />
<xs:element name="remittanceXmlResponse" type="tns:remittanceXmlResponse" />
<xs:complexType name="remittanceXml">
<xs:sequence>
<xs:element minOccurs="0" name="inputXML" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="remittanceXmlResponse">
<xs:sequence>
<xs:element minOccurs="0" name="return" type="xs:string" />
</xs:sequence>
</xs:complexType>
<xs:complexType name="UnsupportedEncodingException">
<xs:sequence>
<xs:element minOccurs="0" name="message" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:schema>
</types>
<message name="remittanceXml">
<part name="parameters" element="tns:remittanceXml" />
</message>
<message name="remittanceXmlResponse">
<part name="parameters" element="tns:remittanceXmlResponse" />
</message>
<message name="UnsupportedEncodingException">
<part name="fault" element="tns:UnsupportedEncodingException" />
</message>
<portType name="rmt_ws">
<operation name="remittanceXml">
<input message="tns:remittanceXml" />
<output message="tns:remittanceXmlResponse" />
<fault name="UnsupportedEncodingException" message="tns:UnsupportedEncodingException" />
</operation>
</portType>
<binding name="rmt_wsBinding" type="tns:rmt_ws">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
<operation name="remittanceXml">
<soap:operation soapAction="" />
<input>
<soap:body use="literal" />
</input>
<output>
<soap:body use="literal" />
</output>
<fault name="UnsupportedEncodingException">
<soap:fault use="literal" name="UnsupportedEncodingException" namespace="" />
</fault>
</operation>
</binding>
<service name="rmt_ws">
<port name="rmt_ws" binding="tns:rmt_wsBinding">
<soap:address location="https://www1.gsis.gr/wsicispay/rmt_ws" />
</port>
</service>
</definitions>
我记得几年前我在 Web 服务的身份验证时遇到了问题,但我不记得在哪里找到了这个替代解决方案:
- 在 Visual Studio 中创建一个新的控制台应用程序(我不确定,如果删除现有项目中的旧服务引用无需手动编辑项目文件等即可工作)
- 像以前一样选择"添加服务引用",但不输入 wsdl 的路径。而是按"高级..."在对话框中和"添加 Web 引用..."在下一个对话框中。
- 在新对话框中输入 wsdl 文件的路径,然后按"添加引用">
在项目中打开文件"program.cs",并在最后一个"using..."之间添加带有命名空间的此类。行和"命名空间....">
namespace TestWeb.WebReference { partial class rmt_ws : System.Web.Services.Protocols.SoapHttpClientProtocol { protected override System.Net.WebRequest GetWebRequest(Uri uri) { System.Net.HttpWebRequest request; request = (System.Net.HttpWebRequest)base.GetWebRequest(uri); if (PreAuthenticate) { System.Net.NetworkCredential networkCredentials = Credentials.GetCredential(uri, "Basic"); if (networkCredentials != null) { System.Diagnostics.Debug.WriteLine("User: " + networkCredentials.UserName); System.Diagnostics.Debug.WriteLine("PW: " + networkCredentials.Password); byte[] credentialBuffer = new UTF8Encoding().GetBytes(networkCredentials.UserName + ":" + networkCredentials.Password); request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(credentialBuffer); } else { throw new ApplicationException("No network credentials"); } } return request; } }
将"TestWeb"(插入代码的第一行)替换为项目的命名空间(通常是项目名称)。
将现有的类"程序"替换为以下代码:
class Program { static void Main(string[] args) { // Fill with a valid xml request String inputXML = ""; String answer = ""; try { WebReference.rmt_ws _webService = new WebReference.rmt_ws(); System.Net.CredentialCache myCredentials = new System.Net.CredentialCache(); // Set correct user and password System.Net.NetworkCredential netCred = new System.Net.NetworkCredential("User", "Password"); _webService.Credentials = netCred.GetCredential(new Uri(_webService.Url), "Basic"); _webService.PreAuthenticate = true; answer = _webService.remittanceXml(inputXML); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.WriteLine(answer); Console.ReadLine(); } }
为您的请求设置具有有效 xml 的输入 XML
- 设置正确的用户和密码
如果这没有帮助,您应该真正提出一个新问题,以找到其他可以提供帮助的人。
我再次联系沟通问题,他们向我发送了这个xml
<?xml version="1.0" encoding="UTF-8"?>
<con:soapui-project id="6026c0c2-d6a6-487f-8551-c5f616d5efab" xmlns:con="http://eviware.com/soapui/config" runType="SEQUENTIAL" abortOnError="false" soapui-version="5.2.1" resourceRoot="" name="pre-prod" activeEnvironment="Default">
<con:settings/>
<con:interface id="dba85261-52fb-48a6-96c0-9fcedc1e8146" name="rmt_wsBinding" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" definition="https://www1.gsis.gr/wsicispay/rmt_ws?wsdl" anonymous="optional" soapVersion="1_1" bindingName="{http://remittance_ws/rmt_ws.wsdl}rmt_wsBinding" type="wsdl" xsi:type="con:WsdlInterface" wsaVersion="NONE">
<con:settings/>
<con:definitionCache type="TEXT" rootPart="https://www1.gsis.gr/wsicispay/rmt_ws?wsdl">
<con:part>
<con:url>https://www1.gsis.gr/wsicispay/rmt_ws?wsdl</con:url>
<con:content>
<![CDATA[
<!--Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Oracle JAX-WS 2.1.5.-->
<!--Generated by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Oracle JAX-WS 2.1.5.-->
<definitions targetNamespace="http://remittance_ws/rmt_ws.wsdl" name="rmt_ws" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tns="http://remittance_ws/rmt_ws.wsdl" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schemas.xmlsoap.org/wsdl/">
<types>
<xsd:schema>
<xsd:import namespace="http://remittance_ws/rmt_ws.wsdl" schemaLocation="https://www1.gsis.gr/wsicispay/rmt_ws?xsd=1"/>
</xsd:schema>
</types>
<message name="remittanceXml">
<part name="parameters" element="tns:remittanceXml"/>
</message>
<message name="remittanceXmlResponse">
<part name="parameters" element="tns:remittanceXmlResponse"/>
</message>
<message name="UnsupportedEncodingException">
<part name="fault" element="tns:UnsupportedEncodingException"/>
</message>
<portType name="rmt_ws">
<operation name="remittanceXml">
<input message="tns:remittanceXml"/>
<output message="tns:remittanceXmlResponse"/>
<fault message="tns:UnsupportedEncodingException" name="UnsupportedEncodingException"/>
</operation>
</portType>
<binding name="rmt_wsBinding" type="tns:rmt_ws">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" style="document"/>
<operation name="remittanceXml">
<soap:operation soapAction=""/>
<input>
<soap:body use="literal"/>
</input>
<output>
<soap:body use="literal"/>
</output>
<fault name="UnsupportedEncodingException">
<soap:fault name="UnsupportedEncodingException" use="literal"/>
</fault>
</operation>
</binding>
<service name="rmt_ws">
<port name="rmt_ws" binding="tns:rmt_wsBinding">
<soap:address location="https://www1.gsis.gr/wsicispay/rmt_ws"/>
</port>
</service>
</definitions>
]]>
</con:content>
<con:type>http://schemas.xmlsoap.org/wsdl/</con:type>
</con:part>
<con:part>
<con:url>https://www1.gsis.gr/wsicispay/rmt_ws?xsd=1</con:url>
<con:content>
<![CDATA[
<!--Published by JAX-WS RI at http://jax-ws.dev.java.net. RI's version is Oracle JAX-WS 2.1.5.-->
<xs:schema version="1.0" targetNamespace="http://remittance_ws/rmt_ws.wsdl" xmlns:tns="http://remittance_ws/rmt_ws.wsdl" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="UnsupportedEncodingException" type="tns:UnsupportedEncodingException"/>
<xs:element name="remittanceXml" type="tns:remittanceXml"/>
<xs:element name="remittanceXmlResponse" type="tns:remittanceXmlResponse"/>
<xs:complexType name="remittanceXml">
<xs:sequence>
<xs:element name="inputXML" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="remittanceXmlResponse">
<xs:sequence>
<xs:element name="return" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
<xs:complexType name="UnsupportedEncodingException">
<xs:sequence>
<xs:element name="message" type="xs:string" minOccurs="0"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
]]>
</con:content>
<con:type>http://www.w3.org/2001/XMLSchema</con:type>
</con:part>
</con:definitionCache>
<con:endpoints>
<con:endpoint>https://www1.gsis.gr/wsicispay/rmt_ws</con:endpoint>
</con:endpoints>
<con:operation id="432ec623-b52f-49b6-bff5-ff220d2dc4e8" name="remittanceXml" anonymous="optional" type="Request-Response" sendsAttachments="false" receivesAttachments="false" inputName="" bindingOperationName="remittanceXml" action="" isOneWay="false">
<con:settings/>
<con:call id="84ad3fc8-b5a2-491b-b375-8fc6d8b5edb4" name="Request 1">
<con:settings>
<con:setting id="com.eviware.soapui.impl.wsdl.WsdlRequest@request-headers"><xml-fragment/></con:setting>
</con:settings>
<con:encoding>UTF-8</con:encoding>
<con:endpoint>https://www1.gsis.gr/wsicispay/rmt_ws</con:endpoint>
<con:request>
<![CDATA[]]>
</con:request>
<con:credentials>
<con:USERNAME>USERNAME</con:USERNAME>
<con:PASSWORD>PASSWORD</con:PASSWORD>
<con:username>USERNAME</con:username>
<con:password>PASSWORD</con:password>
<con:selectedAuthProfile>Basic</con:selectedAuthProfile>
<con:addedBasicAuthenticationTypes>Basic</con:addedBasicAuthenticationTypes>
<con:authType>Global HTTP Settings</con:authType>
</con:credentials>
<con:jmsConfig JMSDeliveryMode="PERSISTENT"/>
<con:jmsPropertyConfig/>
<con:wsaConfig action="http://remittance_ws/rmt_ws.wsdl/rmt_ws/remittanceXmlRequest" version="200508" mustUnderstand="NONE"/>
<con:wsrmConfig version="1.2"/>
</con:call>
</con:operation>
</con:interface>
<con:properties/>
<con:wssContainer/>
<con:oAuth2ProfileContainer/>
</con:soapui-project>
我可以在视觉工作室中使用此文件吗?这对前一个更好吗?