我正在尝试使用 wsdl 文件并获得 soap 响应,但我总是收到错误
HTTP 请求未经授权,客户端身份验证方案"匿名"。从服务器接收的身份验证标头是"Basic Realm"=myrealm。远程服务器返回错误:(401( 未授权
这是我的 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>
这是我打的电话
rmt_ws client = new rmt_wsClient();
using (rmt_wsClient rmt_wsClient = new rmt_wsClient())
{
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
rmt_wsClient.ClientCredentials.UserName.UserName = UserName;
rmt_wsClient.ClientCredentials.UserName.Password = Password;
string messageToSend = "<wsTin>" + wsTin + "</wsTin><wsUser>" + wsUser + "</wsUser>" +
"<wsPswd>" + wsPswd + "</wsPswd><contain><bmrn>" + bmrn + "</bmrn><blrn>" + blrn +
"</blrn><bcnt>" + bcnt + "</bcnt><bafm>" + "bafm" + "</bafm></contain>";
rmt_wsClient.Open();
string responsed = rmt_wsClient.remittanceXml(messageToSend);
rtn = responsed;
}
我在类似的问题中看到,我必须在 app.config 中更改一些内容,但到目前为止我尝试的所有内容都给了我相同的结果。
这是我现在使用的 WcfClinet 中的 app.config 中的部分
<customBinding>
<binding name="rmt_wsBinding1" >
<textMessageEncoding messageVersion="Soap11" />
<httpsTransport maxReceivedMessageSize="2147483647" maxBufferSize="2147483647"/>
</binding>
</customBinding>
<client>
<endpoint address="https://www1.gsis.gr/wsicispay/rmt_ws" binding="customBinding"
bindingConfiguration="rmt_wsBinding1" contract="IcisPayments.rmt_ws"
name="rmt_ws" />
</client>
这是我调用的主程序中的 app.config
<basicHttpBinding>
<binding name ="rmt_wsBinding1">
<security mode="TransportWithMessageCredential" >
<message clientCredentialType="UserName" />
</security>
</binding>
</basicHttpBinding>
<client>
<endpoint address="https://www1.gsis.gr/wsicispay/rmt_ws" binding="basicHttpBinding" bindingConfiguration="rmt_wsBinding1" contract="IcisPayments.rmt_ws" name="rmt_ws" />
</client>
我不知道我是否必须更改我的 WcfClient 中的 app.config 还是有另一个错误。这是我第一次使用 wsdl 文件和 soap 消息。我没有关于我尝试连接的服务器如何工作的任何详细信息。
对于任何有相同问题的人。主要问题是,即使我发送凭据,它也不会将它们作为标头发送。我在问题的上一部分找到了答案 这里感谢H.G.桑德哈根