如何将服务引用添加到WCF客户端Web服务需要客户端身份验证证书

问题描述:

注意,WCF noobie警报

Caution, WCF noobie alert

我需要创建一个WCF客户端来查询非WCF Web服务。
Web服务是不是一个WCF服务。此外,该网络服务需要的客户机身份验证证书。现在,我有证书,并可以创建一个非WCF客户端,完美的作品;我可以添加Web引用,开辟了让我来选择合适的证书的证书对话框,随后又在创建Web引用。力图打造通过添加服务引用WCF客户端则是另一回事,只不过没有一个403拒绝访问错误。

I need to create a WCF client to query a non-WCF web service. The web service is not a WCF service. Additionally, the web service requires a client authentication certificate. Now, I have the certificate, and can create a non-WCF client that works perfectly; I was able to 'Add Web Reference' and a certificate dialog box opened up to allow me to select the appropriate certificate, then went on to create the web reference. Trying to create a WCF client via 'Add Service Reference' is another story, it just fails with a 403 Access Denied error.

我对这个服务的WSDL,并在其上​​运行svcutil.exe的,但我不知道如何从那里继续。

I have the WSDL for the service, and have run svcutil.exe on it, but am not sure how to proceed from there.

感谢您的帮助!

我假设你正在使用的服务进行客户端SSL验证。

I'm assuming that the service you are using is performing client SSL authentication.

由于添加服务引用失败,你可以使用 SvcUtil工具生成WSDL文件客户端,你有。我觉得语法会是这样的:

Since add service reference is failing, you can use svcutil to generate the client from the WSDL file that you have. I think the syntax would be something like:

svcutil *.wsdl /l:C# /out:Reference.cs /config /s /ct:System.Collections.Generic.List`1 /ser:Auto /tcv:Version35 /n:*,<NameOfYourNamespaceHere> /edb

这将生成一个文件,Reference.cs,包含代理类业务(你可以给这个文件任何你想要的名称)。这个文件添加到项目中。一个配置文件,output.config,也将产生。您可以将此配置添加到您的应用程序配置,而不​​是手动输入所有中。

This will generate a file, Reference.cs, that contains the proxy classes to the service (you can give this file whatever name you want). Add this file to your project. A config file, output.config, will also be generated. You can add this configuration to your application configuration instead of typing it all in by hand.

现在您可以按照此MSDN文章使用交通运输安全与证书认证一>。您可以向下跳到客户端部分,在那里它显示了如何将证书附加到code的要求,以及在配置中。

Now you can follow this MSDN article on using Transport Security with Certificate Authentication. You can skip down to the client section where it shows how to attach the certificate to the request in code as well as in configuration.

祝你好运。