HTTP请求未经授权使用客户端身份验证方案' Anonymous'。使用wsdl文件

时间:2018-01-14 08:47:01

标签: c# web-services authentication soap wsdl

我正在尝试使用wsdl文件并获取soap响应,但我总是收到错误

HTTP请求未经授权使用客户端身份验证方案' Anonymous'。从服务器收到的身份验证标头是' 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消息。 我没有关于我尝试连接的服务器如何工作的任何细节。

1 个答案:

答案 0 :(得分:0)

对于有同样问题的人。 主要问题是,即使我发送凭据,它也不会将它们作为标题发送。 我在问题的前一部分找到了答案here 感谢H.G. Sandhagen