C# - Object作为SOAP POST请求中的参数(Basic Auth)

时间:2018-01-21 11:28:01

标签: c# .net soap webrequest

我必须发出SOAP POST请求才能在C#应用程序中创建一个事件。

此端点提供事件管理器服务:

https://eu3.provider.com/eTech/services/cxf/v6/BusinessEventManager

此端点使用SOAP 1.2绑定(Document / literal)和MTOM,并提供以下安全策略:

•通过Base64中的安全通道(https)进行HTTP Basic Auth。

创建活动的方法是createEvents(BusinessEvent[], WSEntry[]),它没有用户名和密码属性。

现在,这是我的代码:

// Creating the BusinessEvent[] object:
BusinessEventManagerWebReference.businessEvent[] myBusinessEvent = new BusinessEventManagerWebReference.businessEvent[1];
myBusinessEvent[0] = new BusinessEventManagerWebReference.businessEvent();

myBusinessEvent[0].id = "myBusinessEvent";

BusinessEventManagerWebReference.coreData cd = new BusinessEventManagerWebReference.coreData();
cd.creationDate = DateTime.Now;
cd.orderingCustomer = "Cliente";
cd.description = "Descripcion";

BusinessEventManagerWebReference.externalReferentialData externalRFD = new BusinessEventManagerWebReference.externalReferentialData();
externalRFD.customerName = "Nombre Cliente";
externalRFD.equipmentName = "Equipo";
cd.referentialData = externalRFD;
myBusinessEvent[0].coreData = cd;

BusinessEventManagerWebReference.location myLocation = new BusinessEventManagerWebReference.location();
myLocation.address = "Direccion";
myLocation.city = "Ciudad";
myLocation.description = "Direccion";
externalRFD.location = myLocation;

// Creating the WebRequest
WebRequest myRequest = WebRequest.Create("https://eu3.provider.com/eTech/services/cxf/v6/BusinessEventManager");
myRequest.Method = "POST";
string usernamePassword = "myuser" + ":" + "mypassword";
usernamePassword = Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword));
CredentialCache mycache = new CredentialCache();
myRequest.Credentials = mycache;
myRequest.Headers.Add("Authorization", "Basic " + usernamePassword);

但是,此时我还不知道如何组合我的WebRequest,我的BusinessEvent对象和用于创建事件的createEvents方法......我应该将BusinessEvent对象作为参数传递吗?我应该在调用WebRespose()??

之前将其转换为XML格式

请帮忙吗?

非常感谢!!

0 个答案:

没有答案