消耗WSDL端点时拒绝错误访问

时间:2018-10-27 17:53:35

标签: c# soap wsdl

我需要访问需要HTTP基本身份验证的 Web服务,并且我使用SoapUI成功使用了。 SoapUI

现在我需要在.net中实现。

我在Visual Studio中创建了一个新的C#控制台项目,并添加了https://itestapi.tracelink.com/soap/snx/snrequest?wsdl的网络参考

下面是我的代码,我访问被拒绝

C#代码

 ServiceReference1.snrequestClient snx = new ServiceReference1.snrequestClient();
            snx.ClientCredentials.UserName.UserName = "abc@gmail.com";
            snx.ClientCredentials.UserName.Password = "xyz@2018";

            ServiceReference1.objectKey objectKey = new ServiceReference1.objectKey
            {
                Name = ServiceReference1.objectIdentifierType.GTIN,
                Value = "1111111"
            };
            ServiceReference1.ReferenceDocuments ReferenceDocuments = new ServiceReference1.ReferenceDocuments();
            snx.serialNumbersRequest("11111", "11111", ServiceReference1.idType.GS1_SER, ServiceReference1.encodingType.SGTIN, 2, objectKey, "", ReferenceDocuments);

App.config

<bindings>
        <basicHttpBinding>
            <binding name="snrequestPortBinding">
              <security mode="Transport">
                <transport clientCredentialType="Basic" />
              </security>
            </binding>
            <binding name="snrequestPortBinding1" />
        </basicHttpBinding>
    </bindings>
    <client>
        <endpoint address="https://itestapi.tracelink.com:443/soap/snx/snrequest"
            binding="basicHttpBinding" bindingConfiguration="snrequestPortBinding"
            contract="ServiceReference1.snrequest" name="snrequestPort" />
    </client>

0 个答案:

没有答案