【发布时间】:2011-08-15 12:03:08
【问题描述】:
我已经看到很多关于这个的问题,我花了一天多的时间研究并试图解决它,但我还是一无所获。
我想将 WCF 服务部署到通过 HTTPS 连接并使用基本身份验证的服务器上。这是我的服务 web.config
我正在使用一个非常简单的计算器作为测试,它有一个方法可以将两个数字相加。
<configuration>
<system.web>
<compilation debug="false" targetFramework="4.0" />
<customErrors mode="Off" />
</system.web>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="UsernameWithTransport">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="Service">
<endpoint address="https://myserver.mydomain.co.uk/CalculatorService"
binding="wsHttpBinding"
bindingConfiguration="UsernameWithTransport"
name="BasicEndpoint"
contract="TestCalculator" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
在 IIS 6.0 中,我启用了基本身份验证并需要 HTTPS。
我可以浏览到 .svc 文件,它会询问我的凭据。我提供它们,它显示默认页面。但是它说:
您已经创建了一个服务。
要测试此服务,您需要创建一个客户端并使用它来 致电服务。您可以使用 svcutil.exe 工具从 命令行语法如下:
svcutil.exe http://myserver.mydomain.co.uk/CalculatorService/Service.svc?wsdl
这将生成一个配置文件和一个代码文件,其中包含 客户端类。将这两个文件添加到您的客户端应用程序并使用 生成的客户端类调用服务。例如:......
基本上,问题似乎在于 .wsdl 的路径是 http:// 而不是 https://,我想我不明白为什么。
我现在正在尝试创建一个 C# 控制台应用程序来测试使用该服务。我无法直接添加对 .svc 路径的引用,因为它只是在循环中四处走动,询问我的用户名和密码。如果我添加对 .svc?wsdl 的引用,那么它确实有效,但随后调用该服务会给出“不允许的方法”,因为它正在尝试使用 HTTP 而不是 HTTPS。
希望我已经充分解释了这一点。感谢您的帮助。
【问题讨论】: