现在困扰我两天了。我已经创建了一个WCF服务,我在本地进行了测试,一切都很好。我购买了一个托管网站,我已将我的WCF上传到托管网站。
当我创建Windows窗体应用程序时。我可以添加一个服务引用,它在配置文件中提供了以下信息:
<system.serviceModel>
<client>
<endpoint address="http://www.verifythisaddress.com/AddressVerification/AddressVerificationService.svc/bh"
binding="basicHttpBinding" bindingConfiguration="bh" contract="AddressVerification.IAddressVerificationService"
name="bh" />
<endpoint address="http://www.verifythisaddress.com/AddressVerification/AddressVerificationService.svc/ws"
binding="wsHttpBinding" bindingConfiguration="ws" contract="AddressVerification.IAddressVerificationService"
name="ws">
<identity>
<servicePrincipalName value="host/win5041.smarterasp.net" />
</identity>
</endpoint>
</client>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IECardBalanceService" />
<binding name="bh" />
</basicHttpBinding>
<wsHttpBinding>
<binding name="ws" />
</wsHttpBinding>
</bindings>
</system.serviceModel>
当我运行此应用程序时,一切正常。
现在,当我接受我的服务时,我把它放在另一个班级。应用程序的根配置文件应该具有相同的绑定吗?所以我将绑定复制并粘贴到根web.config文件中,我收到错误消息,如“访问被拒绝”或“它的http不是https”等等。要注意,我的机器上没有ssl证书。
所以当我调用这个WCF配置文件时:
**<?xml version="1.0"?>
<configuration>
<connectionStrings>
<add name="DBCS" connectionString="cs" providerName="System.Data.SqlClient"/>
</connectionStrings>
<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>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService">
<security mode="Transport" />
</binding>
<binding name="soapEndpointGlobalAddressCheck">
<security mode="Transport" />
</binding>
<binding name="soapSSLEndpointGlobalAddressCheck">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="https://addresscheck.melissadata.net/v2/SOAP/Service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
contract="MelissaDataService.IService" name="BasicHttpBinding_IService" />
<endpoint address="http://address.melissadata.net/v3/SOAP/GlobalAddress"
binding="basicHttpBinding" bindingConfiguration="soapSSLEndpointGlobalAddressCheck"
contract="globalcheck.AddressCheckSoap" name="soapEndpointGlobalAddressCheck" />
<endpoint address="https://address.melissadata.net/v3/SOAP/GlobalAddress"
binding="basicHttpBinding" bindingConfiguration="soapSSLEndpointGlobalAddressCheck"
contract="globalcheck.AddressCheckSoap" name="soapSSLEndpointGlobalAddressCheck" />
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" 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="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpBinding" scheme="http"></add>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
<services>
<service name="AddressVerificationWCF.AddressVerficationService">
<endpoint address="bh" name="bh" binding="basicHttpBinding" contract="AddressVerificationWCF.IAddressVerificationService"></endpoint>
<endpoint address="ws" name="ws" binding="wsHttpBinding" contract="AddressVerificationWCF.IAddressVerificationService"></endpoint>
</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>**
现在,如果我从顶部获取配置,并将其放在我正在运行的其他应用程序的基本配置文件中,并且调用该服务的所有代码与第一个有效的应用程序相同。我得到并且访问被拒绝错误。
我正在调用这样的网络服务:
AddressService.IAddressVerificationService client = new AddressService.AddressVerificationServiceClient("bh");
所以我想弄清楚,为什么它适用于一个,不适用于另一个。任何指针都会非常感激。
我最终会喜欢这样做:
EndpointAddress endpointAddress = new EndpointAddress("http://www.verifythisaddress.com/AddressVerification/AddressVerificationService.svc/bh");
BasicHttpBinding serviceBinding = new BasicHttpBinding(BasicHttpSecurityMode.None);
serviceBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Windows;
serviceBinding.ReceiveTimeout = new TimeSpan(0, 0, 120);
AddressService.IAddressVerificationService client = new AddressService.AddressVerificationServiceClient(serviceBinding, endpointAddress);
答案 0 :(得分:0)
在你的绑定中:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService">
<security mode="None" />
</binding>
<binding name="soapEndpointGlobalAddressCheck">
<security mode="None" />
</binding>
<binding name="soapSSLEndpointGlobalAddressCheck">
<security mode="None" />
</binding>
</basicHttpBinding>
</bindings>
将安全模式设置为none。您还有一些endPoints为
HTTPS://
你可能应该摆脱这些,只使用http://,因为你没有证书。
以下是生成客户端后调用服务所需的全部内容:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="soapEndpointGlobalAddressCheck" />
<binding name="soapSSLEndpointGlobalAddressCheck">
<security mode="None" />
</binding>
<binding name="BasicHttpBinding_IService">
<security mode="Transport" />
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://address.melissadata.net/v3/SOAP/GlobalAddress"
binding="basicHttpBinding" bindingConfiguration="soapEndpointGlobalAddressCheck"
contract="AddressTest.AddressCheckSoap" name="soapEndpointGlobalAddressCheck" />
<endpoint address="https://addresscheck.melissadata.net/v2/SOAP/Service.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService"
contract="AddressVersionTwo.IService" name="BasicHttpBinding_IService" />
</client>
</system.serviceModel>
答案 1 :(得分:0)
第一个serviceModel
列表(有效的列表)未完全集成到最后一个列表中 - 只有绑定似乎已被复制。因此,如果我正确理解了问题,bindings
和endpoints
应完全匹配。如果服务的位置已更改,则只有address
网址应该不同。
此外,最终列表缺少标识部分,这可能是“拒绝访问”消息的原因
<identity>
<servicePrincipalName value="host/win5041.smarterasp.net" />
</identity>