我正在尝试通过https将我的Android应用程序连接到我的webservice并且我一直在
System.Net.WebException:处理网页请求时出错:状态码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
然后我把它发送到SD卡并尝试打开浏览器并从SD卡安装它
但我明白了
413.16您的客户端证书不可信或无效
同时我已经尝试更改服务以使用凭据来查看是否会发生变化。一切都保持不变