如何将 X509Certificate2 附加到网络服务(Apple GSX/C# 特定) [英] How to attach X509Certificate2 to webservice (Apple GSX / C# specific)

查看:20
本文介绍了如何将 X509Certificate2 附加到网络服务(Apple GSX/C# 特定)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Apple 于今年(2015 年)8 月 15 日发布了他们的新一代 WSDL,最大的变化是每次调用 WSDL 都必须使用证书文件进行验证.

Apple released their New Generation WSDL on the 15 of August this year (2015) and the big change was that every call to the WSDL had to be validated with a certificate file.

我已经完成了从 Apple 获取证书的过程,并将我们的服务器 IP 列入白名单,我什至验证了我可以通过使用 HttpWebRequest 编写一个简单的接口来从我们的服务器访问服务端点我可以使用 webRequest.ClientCertificates.Add() 轻松附加证书,因此我知道一切都已准备就绪,可以正常工作了.

I've done the process to get the certificate from Apple, and I've whitelisted our server IP, and I've even verified that I can get access to the service endpoint from our server by coding a simple interface using HttpWebRequest where I easily can attach the certificate using webRequest.ClientCertificates.Add(), so I know everything is ready for it to work.

但是,当我从 下载 WSDL 时,我的问题出现了https://gsxwsut.apple.com/apidocs/prod/html/WSArtifacts.html?user=asp

我将 WSDL 导入 Visual Studio,当我尝试创建客户端类的实例时,我找到的唯一一个是 GsxWSEmeaAspPortClient,这似乎是正确的,因为它具有用于身份验证和各种工具的所有功能,但它没有 ClientCertificates.它确实有包含 ClientCertificate 的 ClientCredentials,但是当我尝试在那里设置证书时,它就像从未设置过一样.

I import the WSDL into Visual Studio and when I try to make an instance of the client class, the only one I find is GsxWSEmeaAspPortClient, which seems to be correct as it has all the functions for authenticate and various tools, but it does not have ClientCertificates. It does have ClientCredentials which have ClientCertificate, but when I try to set the cert there, it's as tho it's never set.

我猜服务代码通过 HttpWebRequest 或 WebRequest 传输数据,所以如果我能从我的类实例 (GsxWSEmeaAspPortClient) 获取请求代码,我可能可以修复它,但我似乎无法解决到达那里.

I'm guessing the service code transmits the data via either HttpWebRequest or WebRequest, so if I just can get to the request code from my instance of the class (GsxWSEmeaAspPortClient) I can probably fix it, but I can't seem to get there.

我看过这个问题:如何使用 WCF 连接 Apple 的 GSX NewGeneration Web 服务? 这表明它真的应该那么简单,但我没有 GsxWSEmeaAspService,只有来自 Visual Studio 的 WSDL 代的 GsxWSEmeaAspPortClient.

I've looked at this question: How can I connect with Apple's GSX NewGeneration webservices with WCF? which suggests it really should be that easy, but I don't have the GsxWSEmeaAspService, only the GsxWSEmeaAspPortClient from my Visual Studio's generation of the WSDL.

如果有人有任何想法可以为我指明通往胜利的任何方向,我将永远感激不尽.

If anyone has any ideas which can point me in any direction towards victory I'd be eternally grateful.

我使用的是 Visual Studio 2013,解决方案是 .Net v4.5.1,如果这有什么区别的话.

I'm using Visual Studio 2013 and the solution is .Net v4.5.1 if that makes any difference.

推荐答案

我在这里粘贴了新代码:

I've pasted new code here:

public void Authenticate() {
    // Use custom binding with certificate authentication
    BasicHttpBinding binding = new BasicHttpBinding(BasicHttpSecurityMode.Transport);
    binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Certificate;
    // Create service endpoint
    // Use proper endpoint address - eg. gsxapi.apple.com for production
    EndpointAddress endpoint = new EndpointAddress("https://gsxapiit.apple.com/gsx-ws/services/emea/asp");
    // Create new service
    Apple.GsxWSEmeaAspPortClient service = new Apple.GsxWSEmeaAspPortClient(binding, endpoint);
    // Set loaded certificate
    service.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2(
        "[PathToContainerFromStep7].p12",
        "[YourPasswordFromStep8]");
    // Create authenticate request object
    Apple.authenticateRequestType auth = new Apple.authenticateRequestType()
    {
        languageCode = "en",
        userId = "[YourAppleServiceAccountNumber]",
        userTimeZone = "[YourTimeZone]",
        serviceAccountNo = "[YourSoldToNumber]"
    };
    // Authenticate to Apple GSX
    Apple.authenticateResponseType session = service.Authenticate(auth);
    // Assign your new session id object
    userSessionId = new Apple.gsxUserSessionType() { userSessionId = session.userSessionId };
}

这篇关于如何将 X509Certificate2 附加到网络服务(Apple GSX/C# 特定)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆