0

我正在尝试通过 https 将我的 android 应用程序连接到我的 web 服务,并且我不断收到

System.Net.WebException:处理 Web 请求时出错:状态码 403(禁止):禁止

浏览器的网络服务似乎很好。我还在 Android 中安装了证书,但我仍然收到浏览器的警告。

这是我的方法

public static string HttpSoap2()
{
    var binding = new BasicHttpBinding () {
        Name= "basicHttpBinding",
        MaxReceivedMessageSize = 67108864,
    };

    binding.ReaderQuotas = new System.Xml.XmlDictionaryReaderQuotas() {
        MaxArrayLength = 2147483646,
        MaxStringContentLength = 5242880,
    };

    var timeout = new TimeSpan(0,1,0);
    binding.SendTimeout= timeout;
    binding.OpenTimeout = timeout;
    binding.ReceiveTimeout = timeout;

    Service1Client client;

    client = new Service1Client(binding, new EndpointAddress(url));

    // This will allow us to ignore the validation of the server-side certificate while maintaining
    // transport encryption. 
    System.Net.ServicePointManager.ServerCertificateValidationCallback += 
    (se, cert, chain, sslerror) => { return true; };

    return client.Greeting ("LOL");
}

这是我的网络配置

<?xml version="1.0"?>
<configuration>

  <appSettings>
    <add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5" />
    <httpRuntime targetFramework="4.5"/>
  </system.web>
  <system.serviceModel>
    <bindings>
      <basicHttpsBinding>
        <binding name="myBinding">
          <security mode="Transport">
            <transport clientCredentialType="Certificate"/>
          </security>
        </binding>
      </basicHttpsBinding>
    </bindings>
    <behaviors>
      <serviceBehaviors>
        <behavior name="myBehaviour">
          <!-- To avoid disclosing metadata information, set the values below to false before deployment -->
          <serviceMetadata httpsGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false        before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="true"/>
        </behavior>
        <!--For debugging purposes set the includeExceptionDetailInFaults attribute to true-->
      </serviceBehaviors>
    </behaviors>
    <protocolMapping>
        <add binding="basicHttpsBinding" scheme="https" />
    </protocolMapping>    
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
  <services>
    <service name="MyHelloService.Service1" behaviorConfiguration="myBehaviour">
      <host>
        <baseAddresses>
          <add baseAddress="https://10.XXX.XX.XX:443"/>
        </baseAddresses>
      </host>
      <endpoint address="" 
                binding="basicHttpsBinding" 
                bindingConfiguration="myBinding" 
                contract="MyHelloService.IService1" />
      <endpoint address="Service1.svc/mex"
                binding="mexHttpsBinding"
                contract="IMetadataExchange" />
    </service>
  </services>       
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
    <!--
        To browse web app root directory during debugging, set the value below to true.
        Set to false before deployment to avoid disclosing web app folder information.
      -->
    <directoryBrowse enabled="true"/>
  </system.webServer>

</configuration>

我忘记了什么吗?

更新
看起来我的证书没有保持安装 我上传了一个从我的自签名导出的 pfx,然后我将它发送到 sdcard 并尝试打开浏览器并从 sdcard 安装它,但我得到这个 413.16 您的客户端证书不受信任或无效

同时,我已经尝试更改服务以使用凭据来查看是否会发生变化。一切都保持不变

4

0 回答 0