我建立了一个简单的项目来测试来自 saber 的 EPS_EXT_ProfileReadRQ 肥皂 api,我可以使用 soapUI 工具很好地使用它。通过 API 检索配置文件的非常简单和基本的场景。使用 VS2013 上的“添加服务引用”来构建我的代理类,然后创建一个简单的接口来实现调用。我的界面如下所示:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using getSabreProfile.EPS_ProfileReadService;
namespace getSabreProfile.Service
{
public interface IGetProfileService
{
Sabre_OTA_ProfileReadRS getProfile(string Token, string Domain, string ProfileId);
}
public class GetProfileService : IGetProfileService
{
private EPS_ProfileReadPortTypeClient service = new EPS_ProfileReadPortTypeClient();
public GetProfileService()
{
}
public Sabre_OTA_ProfileReadRS getProfile(string Token, string Domain, string ProfileId)
{
var _security = new Security
{
BinarySecurityToken = Token
};
var _messageHeader = new MessageHeader
{
From = new From
{
PartyId = new PartyId[1] { new PartyId { Value ="Client" } }
},
To = new To
{
PartyId = new PartyId[1] { new PartyId { Value = "Sabre" } }
},
CPAId = "CL41",
ConversationId = "Profiles",
Action = "EPS_EXT_ProfileReadRQ",
MessageData = new MessageData
{
RefToMessageId = "Profiles Get Profile",
Timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
}
};
var _sabre_OTA_ProfileReadRQ = new Sabre_OTA_ProfileReadRQ
{
Version = "6.19",
Item = new ProfileType
{
TPA_Identity = new ProfileTypeTPA_Identity
{
UniqueID = ProfileId,
DomainID = Domain,
ClientCode = "TN",
ProfileTypeCode = ProfileTypeInfo.TVL,
ClientContextCode = "MYS"
}
}
};
var response = service.EPS_ProfileReadRQ(ref _messageHeader, ref _security, _sabre_OTA_ProfileReadRQ);
return response;
}
}
}
然后我只是从我的程序中实例化接口:
private void btnGetProfile_Click(object sender, EventArgs e)
{
GetProfileService _getProfile = new GetProfileService();
var res = _getProfile.getProfile(tbToken.Text, tbDomain.Text, tbProfileId.Text);
}
该应用程序编译时没有错误,但在运行时出现错误:
There was an error in serializing one of the headers in message EPS_ProfileReadRQRequest: 'Unable to generate a temporary class (result=1).
error CS0030: Cannot convert type 'getSabreProfile.EPS_ProfileReadService.IgnoreReadSubjectAreasType' to 'getSabreProfile.EPS_ProfileReadService.PartialReadSubjectAreasType'
error CS0029: Cannot implicitly convert type 'getSabreProfile.EPS_ProfileReadService.PartialReadSubjectAreasType' to 'getSabreProfile.EPS_ProfileReadService.IgnoreReadSubjectAreasType'
在我看来,VS2013 没有正确生成 Web 服务的代理类,并且类型映射没有正确解析,但我一直在寻找解决方案。我愿意手动调整代理类代码,但不知道在哪里改变,什么大声笑!..我希望有人能在这里提供帮助。
谢谢!