使用来自 Windows Phone 7 的自签名证书使用服务 WCF 错误
我想将 Azure 上运行的 WCF 服务从 http
切换到 https
,但是当我尝试使用 Windows Phone 7 中的服务时,出现以下错误:
https://xxxxx.cloudapp.net/MainService.svc 可以接受消息。这通常是由不正确的地址或 SOAP 操作引起的。有关更多详细信息,请参阅 InnerException(如果存在)。
我创建了与服务 uri 同名的自签名证书,然后通过电子邮件将证书发送到 Windows Phone 并安装它。但我不断收到此消息,即使是来自模拟器和真实手机。
使用服务可以在 WPF 和桌面 Silverlight 应用程序中运行。
WP 配置
ServiceReferences.ClientConfig
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IGEOService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="TransportWithMessageCredential" />
</binding>
<binding name="BasicHttpBinding_IAccountService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="TransportWithMessageCredential" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://xxxxx.cloudapp.net/MainService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGEOService"
contract="ServiceReference1.IGEOService" name="BasicHttpBinding_IGEOService" />
<endpoint address="https://xxxxx.cloudapp.net/MainService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAccountService"
contract="ServiceReference1.IAccountService" name="BasicHttpBinding_IAccountService" />
</client>
</system.serviceModel>
在服务器上
clientaccesspolicy.xml
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="http://*" />
<domain uri="https://*" />
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
服务配置 服务
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="Diplomka" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="1" osVersion="*">
<Role name="MainWFCRole">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
</ConfigurationSettings>
<Certificates>
<Certificate name="diplomka.cloudapp.net" thumbprint="539B9A0149DC1221F0F4ECA79BAD84073BF1D650" thumbprintAlgorithm="sha1" />
</Certificates>
</Role>
<Role name="WebKlient">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
定义
enter code here
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="Diplomka" xmlns="http://schemas.microsoft.com/ ServiceHosting/2008/10/ServiceDefinition">
<WebRole name="MainWFCRole">
<Sites>
<Site name="Web">
<Bindings>
<Binding name="Endpoint1" endpointName="Endpoint1" />
</Bindings>
</Site>
</Sites>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="https" port="443" certificate="diplomka.cloudapp.net" />
</Endpoints>
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<LocalResources>
<LocalStorage name="MainWFCRole.svclog" sizeInMB="1000" cleanOnRoleRecycle="false" />
</LocalResources>
<Certificates>
<Certificate name="diplomka.cloudapp.net" storeLocation="LocalMachine" storeName="My" />
</Certificates>
</WebRole>
<WebRole name="WebKlient">
<Sites>
<Site name="Web">
<Bindings>
<Binding name="Endpoint1" endpointName="Endpoint1" />
</Bindings>
</Site>
</Sites>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="http" port="80" />
</Endpoints>
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
</WebRole>
Web 配置
enter code here
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<services>
<service name="MainWFCRole.MainService" behaviorConfiguration="sb1">
<endpoint binding="basicHttpBinding" contract="MainWFCRole.IGEOService" bindingConfiguration="binding1"/>
<endpoint binding="basicHttpBinding" contract="MainWFCRole.IAccountService" bindingConfiguration="binding1"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<!--secure wcf by TransportWithMessageCredential security-->
<binding name="binding1">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="sb1">
<!---->
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MainWFCRole.AccountValidator,MainWFCRole"/>
</serviceCredentials>
<!--Enable https metadata exchange endpoint-->
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
I wanted to switch my WCF service running on Azure from http
to https
, but when I try to consume service from Windows Phone 7 I get this err:
There was no endpoint listening at https://xxxxx.cloudapp.net/MainService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
I have created self-signed certificate with the same name as the service uri, then send the certificate to Windows Phone by email and installed it. But I keep getting this message, even from the emulator as well as the real phone.
Consuming services works both from WPF and desktop Silverlight applications.
WP config
ServiceReferences.ClientConfig
<configuration>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IGEOService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="TransportWithMessageCredential" />
</binding>
<binding name="BasicHttpBinding_IAccountService" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647">
<security mode="TransportWithMessageCredential" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://xxxxx.cloudapp.net/MainService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IGEOService"
contract="ServiceReference1.IGEOService" name="BasicHttpBinding_IGEOService" />
<endpoint address="https://xxxxx.cloudapp.net/MainService.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IAccountService"
contract="ServiceReference1.IAccountService" name="BasicHttpBinding_IAccountService" />
</client>
</system.serviceModel>
On server
clientaccesspolicy.xml
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="http://*" />
<domain uri="https://*" />
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>
Service configuration
<?xml version="1.0" encoding="utf-8"?>
<ServiceConfiguration serviceName="Diplomka" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="1" osVersion="*">
<Role name="MainWFCRole">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
</ConfigurationSettings>
<Certificates>
<Certificate name="diplomka.cloudapp.net" thumbprint="539B9A0149DC1221F0F4ECA79BAD84073BF1D650" thumbprintAlgorithm="sha1" />
</Certificates>
</Role>
<Role name="WebKlient">
<Instances count="1" />
<ConfigurationSettings>
<Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
</ConfigurationSettings>
</Role>
</ServiceConfiguration>
Serivce definiton
enter code here
<?xml version="1.0" encoding="utf-8"?>
<ServiceDefinition name="Diplomka" xmlns="http://schemas.microsoft.com/ ServiceHosting/2008/10/ServiceDefinition">
<WebRole name="MainWFCRole">
<Sites>
<Site name="Web">
<Bindings>
<Binding name="Endpoint1" endpointName="Endpoint1" />
</Bindings>
</Site>
</Sites>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="https" port="443" certificate="diplomka.cloudapp.net" />
</Endpoints>
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
<LocalResources>
<LocalStorage name="MainWFCRole.svclog" sizeInMB="1000" cleanOnRoleRecycle="false" />
</LocalResources>
<Certificates>
<Certificate name="diplomka.cloudapp.net" storeLocation="LocalMachine" storeName="My" />
</Certificates>
</WebRole>
<WebRole name="WebKlient">
<Sites>
<Site name="Web">
<Bindings>
<Binding name="Endpoint1" endpointName="Endpoint1" />
</Bindings>
</Site>
</Sites>
<Endpoints>
<InputEndpoint name="Endpoint1" protocol="http" port="80" />
</Endpoints>
<Imports>
<Import moduleName="Diagnostics" />
</Imports>
</WebRole>
web config
enter code here
<configuration>
<system.diagnostics>
<trace>
<listeners>
<add type="Microsoft.WindowsAzure.Diagnostics.DiagnosticMonitorTraceListener, Microsoft.WindowsAzure.Diagnostics, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
name="AzureDiagnostics">
<filter type="" />
</add>
</listeners>
</trace>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"/>
</system.web>
<system.serviceModel>
<services>
<service name="MainWFCRole.MainService" behaviorConfiguration="sb1">
<endpoint binding="basicHttpBinding" contract="MainWFCRole.IGEOService" bindingConfiguration="binding1"/>
<endpoint binding="basicHttpBinding" contract="MainWFCRole.IAccountService" bindingConfiguration="binding1"/>
</service>
</services>
<bindings>
<basicHttpBinding>
<!--secure wcf by TransportWithMessageCredential security-->
<binding name="binding1">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="sb1">
<!---->
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="MainWFCRole.AccountValidator,MainWFCRole"/>
</serviceCredentials>
<!--Enable https metadata exchange endpoint-->
<serviceMetadata httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
</system.webServer>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
![扫码二维码加入Web技术交流群](/public/img/jiaqun_03.jpg)
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论